Two gay men in Indonesia's conservative Aceh Province were publicly caned outside a mosque in front of thousands of spectators on Tuesday.

It marked the first such punishment to be meted out to gay people in Aceh, the only province that applies Islamic sharia law, since a local bylaw against same-sex relationships went into effect in 2014.

The men, caught in bed together by vigilantes in March, received 83 lashes each in the front yard of the Syuhada Mosque in Banda Aceh, the provincial capital.

The men, aged 20 and 24, were sentenced last week by the Banda Aceh Sharia Court to 85 lashes. But the number of lashes was reduced by two -- or one per month --after taking into consideration that they spent two months in prison already.

Aceh is the only province in Indonesia allowed to apply sharia law under a special autonomy law enacted in 2001 as part of a peace deal reached between the government and separatist rebels.

While gay sex is not illegal elsewhere in the world's most populous Muslim country, Jakarta police on Sunday raised a gay sauna and detained 141 men, including several foreigners.

Of the 15 who remain in detention, 10 have been charged under the country's 2008 Law on Pornography "for exhibiting themselves or someone else in public by showing nudity," which is punishable by up to 10 years imprisonment.

The move has been criticized by human rights activists, who alleged that some of the men were subjected to humiliating treatment by being stripped and photographed, with those photos spread on social media.