The men become the country's first gay couple to face trial for breaching homosexuality laws in Aceh state.
A court in Indonesia's Aceh province on Wednesday sentenced two men to 85 lashes of the cane for having a sexual relationship.
The public caning handed down by a panel of judges is the first time laws against homosexuality have been used in the province.
In 2014, Aceh enacted a law that punishes anybody caught having a gay relationship to 100 lashes, 100 months in jail or a fine of 1,000 grams of gold.
Aceh is the only province in Muslim-majority Indonesia that criminalises same-sex relations and that uses Sharia as its legal code in addition to the national criminal code.
"The defendants are proven to have committed sodomy and are found guilty," the presiding judge, Khairil Jamal, said.
The pair, aged 20 and 23, were caught together in bed in March by vigilantes who burst into the boarding house where they were staying in the provincial capital Banda Aceh.
The vigilantes handed the men over to Sharia authorities who said the pair admitted to being in a relationship and having had sex three times.
Human Rights Watch called on Indonesia to release the men.
"The verdict will increase fear among LGBT people not only in Aceh but also in many other, especially conservative, provinces ... in Indonesia," HRW's Indonesia researcher, Andreas Harsono said.
The lesbian, gay, bisexual and transgender (LGBT) community in Indonesia has faced growing pressure since high-ranking government officials last year expressed reservations about activism by its members.
Authorities in Aceh province on the northern tip of Sumatra island caned 339 people in 2016 for a range of crimes, according to HRW.
Religious police in Aceh have also been known to target Muslim women without head scarves or those wearing tight clothes, and people drinking alcohol or gambling.