Religious police in Indonesia publicly caned two men Tuesday for having consensual gay sex.

The men received more than 80 lashes each, inflicted by hooded men inside a mosque in the city of Banda Aceh as hundreds of people watched, many of them recording the scene on mobile phones.

"The convicts will be returned to their family after being caned publicly as the caning is considered a social sanction," Yusnardi, head of the Sharia police force in the conservative province of Aceh, told reporters. "Hopefully it will be a deterrent for people not to do anything against Islamic law".

“Flogging sentences and the criminalization of same sex relations are both flagrant violations of international human rights law," Amnesty International’s Deputy Director for Southeast Asia and the Pacific Josef Benedict said. "The international community must put pressure on Indonesia to create a safer environment for the LGBTI community before the situation deteriorates further. Nobody should be punished for consensual sex.”

The two men were arrested in March after local residents who suspected they were gay broke into their rented room and found them having sex.

Homosexuality is not illegal in Indonesia, but Aceh, the most conservative province in the Muslim-majority country, introduced anti-homosexuality laws in 2014.

Tuesday's public caning marked the first application of the law; however, hundreds were also caned for offenses including gambling, drinking alcohol, and women wearing tight clothing in 2016.