A bid to make all sex outside marriage illegal was thrown out by an Indonesian court Thursday, as concerns grow over rising intolerance in the world's biggest Muslim-majority country.
Five out of nine judges on the Constitutional Court in the capital Jakarta narrowly rejected the push to criminalise extramarital relations.
The unsuccessful petition would have affected unmarried heterosexuals and gay people, who cannot marry in Indonesia -- several months after the arrests of a group of men accused of holding a "gay party".
The court heard a judicial review filed by Islamic activist group the Family Love Alliance that sought to alter the criminal code.
"The appeal is rejected in its entirety," said the Constitutional Court's chief justice Arief Hidayat.
Under current laws, sex is only illegal in Indonesia for both homosexual and heterosexual people if it involves a minor.
However, gay sex is illegal in conservative Aceh province, which upholds sharia law. Under a local law that came into force in 2015, people can also be punished for having gay sex with up to 100 strokes of the cane.
Aceh, on Sumatra island, began implementing Islamic law after being granted special autonomy in 2001, an attempt by the central government to quell a long-running separatist insurgency.
There was a backlash against the country's LGBT community last year with government ministers publicly making anti-gay statements.
In May, police arrested a group of men holding party in two hotel rooms in Surabaya, Indonesia's second-biggest city.
Some of the men were watching gay porn and performing "deviant sexual acts", police said at the time.
Authorities named eight men as suspects and filed preliminary charges against them under Indonesia's tough anti-pornography law, which can result in years in jail.
Also this year, two men having sex were caught by a group of vigilantes who raided a boarding house in Aceh.
Indonesia has often been praised for its moderate inclusive brand of Islam, and the constitution guarantees freedom of worship for six religions.
However, the diverse archipelago's sizeable religious minorities -- mainly Christians and Muslim minority Shiites and Ahmadis -- have been increasingly targeted in recent years.