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 cellphones as a team of five robed and hooded enforcers took turns to inflict the punishment, relieving one another after every 20 strokes for one of the men and 40 for the other.

Sarojini Mutia Irfan, a female university student who witnessed the caning, said it was a necessary deterrent.

“What they have done is like a virus that can harm people’s morale,” she said. “This kind of public punishment is an attempt to stop the spread of the virus to other communities in Aceh.”

The couple were arrested in March after neighbourhood vigilantes in the provincial capital, Banda Aceh, suspected them of being gay and broke into their rented room to catch them having sex.

A Shariah court last week sentenced each man to 85 strokes, but they were caned 83 times after a remission for time spent in prison. Four heterosexual couples also were caned on Tuesday, receiving a far lesser number of strokes for affection outside marriage.

Banda Aceh resident Ibrahim Muhayat said far more people attended the publicly meted-out punishment than usual because like him, many wanted to witness Indonesia’s first-ever caning of gay men.

The Islamic Defenders Front, a hard-line group known for acts of vigilante violence throughout Indonesia, erected a banner at the mosque that declared the group was ready to defend Shariah law whatever the cost.

With the exception of Aceh, homosexuality is not illegal in Indonesia, but the country’s low-profile LGBT community has been under siege in the past year.

Prejudice has been fanned by stridently anti-gay comments from politicians and Islamic hardliners, and a case before the country’s top court is seeking to criminalise gay sex and sex outside marriage. On Monday, 141 men were detained in a police raid on a gay sauna in Jakarta, the capital.

New York-based Human Rights Watch said the caning was torture under international law and had called on Indonesian President Joko “Jokowi” Widodo to intervene.

Caning is also a punishment in Aceh for gambling, drinking alcohol, women who wear tight clothes and men who skip Friday prayers.

More than 300 people were caned for such offences in 2016. Indonesia’s reputation for practising a moderate form of Islam has been battered in the past year due to attacks on religious minorities, a surge in persecution of gays and a polarising election campaign for governor of Jakarta that highlighted the growing strength of hard-line Islamic groups.

Earlier this month, the outgoing Jakarta governor, a minority Christian, was sentenced to two years in prison for campaign comments deemed as blaspheming the Koran.

Australian Foreign Minister Julie Bishop’s office told Buzzfeed in a statement: “The foreign minister has raised with the Indonesian government Australia’s serious concerns about the caning of two gay men under sharia Law in Indonesia’s Aceh province.”

“Earlier this month, the Australian government recommended that Indonesia reject discrimination on any grounds including sexual orientation and gender identity during Indonesia’s UN Human Rights Council Universal Periodic Review.”

This article originally appeared in The New Zealand Herald.