A Tunisian court sentenced six students to three years in jail, each, on charges of sodomy in a judgement condemned by human rights activists.
The students' lawyer Boutheina Karkni said on Monday the young men were detained in November and December after "neighbours denounced them".
They were made to undergo anal examinations - a routine order in Tunisia for men accused of engaging in same-sex relations in an attempt to find "proof" of sodomy. The method has been discredited as unscientific, according to rights group Amnesty International.
A court in the city of Kairouan handed down the maximum jail terms last week under a controversial article of the criminal code that criminalises sex between two males, Karkni told the AFP news agency.
| Empire - Tunisia: A revolutionary model?
The six are also banned from the central city for five years when they finish their jail time, she said.
One of the defendants was given an extra six months behind bars for "offensive" videos found on his computer, the huffpostmaghreb.com news site reported.
Karkni described the ruling as "extremely harsh" and said an appeal hearing should take place "in two to three weeks" in the nearby coastal city of Sousse.
Local rights group Shams - which calls for decriminalising homosexuality in Tunisia by revising Article 230 of the penal code - condemned the judgement.
However, interior ministry spokesman Walid Louguini defended the ruling. "Our job is to uphold the law," radio station Shems FM quoted him as saying.
Amnesty also denounced the prosecutions, saying the case highlighted the country's "entrenched homophobia".
"The verdict against these men is absolutely shocking, especially at a time when rights groups in Tunisia are increasingly speaking out against the criminalisation of same-sex sexual relations," said Said Boumedouha, Amnesty's deputy director for the Middle East and North Africa.
In September, a Tunisian court sentenced a student to a year behind bars in Sousse on charges of homosexuality, also after an anal exam.
He was released in November pending an appeal hearing expected on Thursday.