The pair, aged 20 and 23, were sentenced to 85 strokes of the cane each after being found guilty of breaking Aceh's strict Islamic laws.
They were caught together in bed in March by vigilantes who burst into the boarding house where they were staying in provincial capital Banda Aceh.
Presiding judge Khairil Jamal told the court that the men had been "proven legally and convincingly guilty of committing gay sex, the defendants are sentenced to 85 strokes of the cane in public".
Aceh is the only part of Indonesia, which has the world's biggest Muslim population, that is allowed to implement sharia law and public canings for offences ranging from gambling to drinking alcohol were already common.
More From This Section
But the men found guilty Wednesday will be the first to be subject to the punishment for gay sex, which was banned in Aceh under a regulation introduced in 2015. Gay sex is not illegal in the rest of Indonesia.
The verdict is the latest example of growing hostility towards Indonesia's small lesbian, gay, bisexual and transgender (LGBT) community, which faced a backlash last year with government ministers publicly making anti-gay statements.
They were then turned over to the sharia police. Authorities said the pair admitted to being in a relationship and having had sex three times.