Two men, aged 20 and 23, have been caned in Indonesian province of Banda Aceh, one of the most conservative parts of the country.

The men were punished for having gay sex, which is illegal in Aceh which enforces Islamic laws. It is not illegal anywhere else in Indonesia.

“Homosexuality is not illegal under Indonesian national law, but the LGBT community has come under pressure since government officials expressed reservations last year about activism by its members,” Reuters reports.

The two men, who were not identified, were found in bed by vigilantes who had invaded their private accommodation in March.

As the two men were brought to a stage outside a mosque where the caning would take place, a large crowd of 1,000 people gathered to witness the event. Many in the crowd recorded the caning on their smartphones, with some laughing and cheering as the punishment was meted out.

Each of the men was caned 82 times by masked men.

The crowd was warned by the authorities not to attack the men, saying that the two were “also human.”

Among the crowd was Sarojini Mutia Irfan, a female university student.

She said the caning 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.”

Human rights activists, however, denounced the punishment as “medieval torture”.

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

The punishment marks the first time the anti-homosexuality law has been enforced in such a way since the law was introduced in 2014.

The BBC reports:

“Rights groups have strongly criticised prosecutions of people involved in same-sex relationships, and the use of caning.

“Amnesty International said every human was entitled to a right to privacy and to have consensual relations, but that the two men had been ambushed in their home.

“It said caning was a “cruel, inhuman and degrading punishment” and may amount to torture and called on the Acehnese authorities to abandon the practice.”

The BBC’s Rebecca Henschke recounts how she met one of the men before the caning:

I met one of the young men in jail a day before the caning, the first journalist to speak to him. He was terrified and his whole body was shaking. He was thin, pale and had a red rash on his skin.

Inmates surrounded us with intimidating glares as we tried to talk. I thought we were going to be speaking in a private room, but he was not granted that.

Before neighbourhood vigilantes broke down the door to his rented room, he was in his final years of a medical degree – his plan was to be a doctor. Now we are told the university has kicked him out.

Videos of the raid that caught him and his partner having sex have been widely shared online. In the mobile phone footage they are both naked, pleading for help.

“I just want the caning to be over and to go back to my family, I have been deeply depressed. I am trying to pull myself out of a deep black hole,” he said.