Two men in Indonesia's Aceh province were publicly caned dozens of times on Tuesday for consensual gay sex, a punishment that intensifies an anti-gay backlash in the world's most populous Muslim country and which rights advocates denounced as "medieval torture."

More than a thousand people packed the courtyard of a mosque to witness the caning, which was the first time that Aceh, the only province in Indonesia to practice Shariah law, has caned people for homosexuality.

The crowd shouted insults and cheered as the men, aged 20 and 23, were whipped across the back and winced with pain. Many in the crush of spectators filmed the caning with mobile phones as a team of five robed and hooded enforcers took turns inflicting the punishment, relieving one another after every 20 strokes for one of the men and 40 for the other.