Two men in Indonesia's Aceh province have been publicly caned dozens of times for consensual gay sex, a punishment rights advocates denounced as "medieval torture" and escalates an anti-gay backlash.

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

The men, aged 20 and 23, were arrested in March after vigilantes broke into their rented room to catch them having sex.

A Shariah court last week sentenced each man to 85 strokes. Heterosexual couples also were caned Tuesday, for affection outside marriage.

Indonesia's LGBT community has been under siege in the past year. Prejudice has been fanned by stridently anti-gay comments from politicians and Islamic hard-liners.