In what is believed to be the first time in Indonesia's history, a gay couple have been sentenced to public caning after they were caught having sex.

A Shariah court in the country's Aceh province on Wednesday, 17 May, said that the men – aged 20 and 23 – would each be subjected to at least 85 lashes for having a sexual relationship. Lead prosecutor in the case, Gulmaini, said that the duo will be caned next week, before Ramadan, which starts on 25 May.

The chief judge, Khairil Jamal, said the men were "legally and convincingly proven to have committed gay sex".

The three-judge panel had earlier decided to give 100 lashes each to the men, but that was reduced to 85 because of their polite and co-operative behaviour in the court, he added.

"As Muslims, the defendants should uphold the Shariah law that prevails in Aceh," Jamal said.

The men were arrested after neighbourhood vigilantes caught them having sex. They were also reportedly filmed by the vigilantes, who produced the video as evidence in court.

The video was also shared online, which shows one of the men naked. He is seen trying to make calls seeking help, while his partner is seen being pushed repeatedly by a man in an attempt to prevent the couple from leaving the room.

The sentencing of the couple coincidentally came on the International Day against Homophobia and Transphobia.

International human rights groups have condemned the ruling and said it was an abusive and humiliating experience for the men. They have also called for their immediate release.

Aceh is the only province in Muslim-majority Indonesia, which still practices Shariah law. The law was a concession made by the government in 2006 to end a war with separatists.

Homosexuality in Indonesia
A gay couple has been sentenced to public caning after they were caught having sex in Indonesia - Representational image Jewel Samad/AFP/Getty Images

Caning is one of the most brutal punishments under the law, which is also given to those who drink alcohol, and skip Friday prayers. Women who wear tight clothes can also be subjected to caning.

Over 300 people were reportedly caned for such offenses in 2016.

The latest incident followed the sentencing of a minority Christian governor on blasphemy charges. The country is currently divided over the issue, with many rights groups demanding the withdrawal of the two-year jail sentence for Jakarta governor Basuki Tjahaja Purnama, also known as Ahok.