JAKARTA, Indonesia - Indonesia's top court on Thursday ruled against petitioners seeking to make gay sex and sex outside marriage illegal in a victory for the country's besieged LGBT minority.

The 5-to-4 decision of the nine-judge panel of the constitutional Court rejected the arguments of a conservative group, the Family Love Alliance, which believes Indonesia is being swamped by immoral behaviour, fueled by the internet and social media. Members of the group wept as it became clear the court would not side with them.

Rights advocates had feared judges would criminalize tens of millions of people by outlawing gay and extramarital sex, setting back human rights in the world's most populous Muslim nation. Separately, some lawmakers are seeking to make homosexuality a crime in an amended criminal code that might be considered by parliament next year.

In the past two years, LGBT Indonesians have endured a wave of hostility that has been stoked by inflammatory public statements from conservative officials and religious groups. Police have raided gay clubs and private parties, charging those arrested under Indonesia's broad anti-pornography laws. Aceh, a semiautonomous province that practices Shariah law, caned two young men for gay sex before a baying crowd of thousands in May after vigilantes broke into their home and handed them over to religious police.

Naila Rizqi Zakiah, a lawyer at the Community Legal Aid Institute in Jakarta who argued against criminalization, said the case was important for democracy and human rights in Indonesia.

"It's such a big verdict," she said. "It means that the constitutional Court is consistently strengthening its position as the guardian of the Constitution and also as protector of human rights."

The judges in their ruling said it's not the constitutional Court's role to criminalize private behaviour or to usurp parliament by imposing laws on it. The court's decision is final.

Judge Saldi Irsa said the petitioners were in effect asking the court to formulate a new criminal code because they feared parliament would took take too long to enact changes wanted by the Family Love Alliance.

"The argument that the process of formulating legislation takes a long time could not be justification for the constitutional Court to take over the authority of lawmakers," he said.

In a dissenting opinion, four judges argued to outlaw same-sex relations and sex outside marriage on morality grounds.

Euis Sunarti from the Family Love Alliance said they were saddened by the failure of their case.

"We are working on the ground level and know exactly the magnitude of this problem on the ground," she told reporters.