“Cane him on the ass so it won’t happen again!” onlookers shouted, according to Vice News. “Hit him harder!”

The crowd reportedly cheered with each strike of the cane on their backs by five hooded executioners who swapped to prevent tiring.

One man managed to stand until the end of the ordeal, which human rights groups say amounts to torture, while the second broke down.

They were each given 83 strokes – two short of the sentence – as after a remission for time already spent in prison.

Four heterosexual couples had been lashed first to cheers under lesser sentences for violating Islamic laws forbidding contact between unmarried couples.

Many in the crush of spectators filmed the caning with mobile phones, months after footage of the men naked in a rented room was used as evidence to convict them.

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.”

Members of the Islamic Defenders Front, a hard-line group known for vigilante attacks on shops, bars, nightclubs, non-Muslims, secular campaigners and LGBT activists.

They erected a banner at the mosque that declared the group was ready to “defend” Sharia law, whatever the cost.

The men were arrested in March after local Banda Aceh broke into their rented room to catch them having sex, taking video that showed the men naked and begging to be freed.

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

“The court’s less-than-maximum sentence of 85 lashes is no act of compassion. It does not change the reality that flogging is a grotesque display of medieval torture,” said Phelim Kine, the group’s deputy Asia director.

It is the only province in Indonesia to practice Sharia laws brought in two years ago as a concession made by the national government in 2006, aiming to end a war with separatists.

Reforms allow members of the public as well as the special Sharia police to publicly identify and detain anyone suspected of violating its rules, which specifically outlaw liwath (sodomy) and musahabah (lesbian sex).

They have seen several LGBT suspects detained, including two teenage girls arrested in 2015 on suspicion of being lesbians after embracing in public, as the state parliament has gradually adopted hardline laws to criminalise women who do not wear headscarves, drinking alcohol, gambling, and extramarital sex.

Homosexuality is not illegal elsewhere in Indonesia but a case before the country’s Constitutional Court is seeking to criminalise consensual same-sex relations and sex outside marriage.

On Monday, 141 men were detained in a police raid on a gay sauna in Jakarta, with several filmed and photographed by police in what campaigners said was deliberate public shaming.

It came weeks after police in Surabaya, Indonesia’s second-largest city, arrested 14 men at what they alleged was a sex party and forced them to have HIV tests.

Indonesia’s reputation for tolerance is already under scrutiny after the governor of Jakarta, a Christian, was sentenced to two years in prison for alleged blasphemy.

There are growing fears that Islamists including the Islamic Defenders Front are in the ascendancy in a country home to sizeable communities of Hindus, Christians, Buddhists and other minorities.

As well as home-grown groups, Indonesia is among the Asian nations targeted for expansion by Isis, which launched an attack in Jakarta in January 2016.