Shinta Ratri, a leader of an Islamic school for transgender people, at her house in Yogyakarta, Indonesia. Authorities closed down the school and have been taking a hard line on homosexuality. (Ulet Ifansasti/Getty Images)

Indonesia’s highest court is deliberating whether sex outside marriage should be made illegal in the world’s third-largest democracy, in the latest push by conservative Islamist organizations to restructure the country’s relatively secular legal code.

If the court revises the law to forbid casual sex, gay sexual relations would become illegal for the first time in Indonesian history, and straight unmarried couples could face prosecution.

The Family Love Alliance, a conservative Islamist advocacy organization, petitioned the Constitutional Court to broaden existing Indonesian law, which makes adultery illegal but does not ban sexual relations between unmarried people. A decision is expected in December or early next year, after the court hearings are completed.

Human rights organizations say the situation is very dangerous for Indonesia, which has a larger Muslim population than any other country. “This [petition] consists of discrimination towards all Indonesians: women as well as men, and those of diverse sexual orientations,” Bahrain, who goes by one name and is the director of advocacy at the Legal Aid Center, told the court at a hearing in early October. The center is one of several progressive advocacy organizations arguing against revising the constitution to ban sex outside marriage.

A ban would “criminalize consensual sex outside of marriage,” said Naila Rizqi, head of legal affairs at the National Commission on Women. The current law punishes adultery with up to nine months in prison, and if the law is revised, that penalty could carry over to unmarried sexual partners who have been prosecuted and convicted.

The case is the latest battle in the struggle over Indonesia’s ­social culture, which features a small band of progressives battling to maintain this Muslim-majority democracy’s relatively secular legal system against Islamist forces.

Activists fear that Indonesia’s highly conservative court will be unable to resist the opportunity to strike a blow for traditional morality. In an early court hearing, one conservative judge, Patrialis Akbar, appeared to affirm arguments made by conservative plaintiffs, saying, “Our freedom is limited by moral values as well as religious values. . . . We’re not a secular country — this country acknowledges religion.”

Although Indonesia, a rare ­example of a vibrant Muslim-majority democracy, does not maintain Islamic law at the national level, Indonesian conservatives interpret their country’s constitution to support loosely defined religious values.

Over the past 1½ years, gays have become a particular target of these religious values, with state officials and Islamic scholars repeatedly declaring that lesbian, gay, bisexual and transgender people represent an unprecedented danger to the health of Indonesian society. Over the past few weeks, expert witnesses have given emotion-laded testimony on the danger gays pose to Indonesia.

“Can LGBT refrain from . . . free sex with constantly changing partners? They cannot. LGBT represents sex, sex, sex,” Dewi Inong Irana, a doctor, told the court, citing her experience with gay and transgender patients. Dewi also warned the court about the dangers of the gay hookup app ­Grindr, which has since been banned by the government. “We have to protect this nation, ladies and gentlemen. Grindr is already here,” she said.

One witness, a Muslim scholar and anti-LGBT activist named Adian Husaini, suggested that the spread of gay rights is the result of a Jewish conspiracy. “Those who conducted the movement to legalize [same-sex marriage] were a small group of Jews in America,” he told the court. He cited a speech that Vice President Biden gave to Jewish leaders thanking them for their support for gay equality.

A lesbian activist, Lini Zurlia, sat outside the courtroom one recent day because of the overflowing crowd, wearily observing the hearing on a screen. “We can only laugh,” she said. “They don’t understand us and don’t want to understand us.”

But she worried that the Islamists would prevail. “Of the nine judges, only two judges have a solid perspective on the law. Seven of them ask questions that aren’t about legality or constitutionality but instead about religion or moral perspectives,” she said.

Nor is the LGBT community the only one at risk in this battle in Indonesia’s culture wars. Women’s advocates worry that a ban on sex outside marriage would be used disproportionately to prosecute women, in part because unmarried pregnant women would be an easy target. “It’s obvious this law will be a disaster, and women will be most affected,” said Tunggal Pawestri, a women’s rights activist.

Another worry about the court case, according to Santi Kusumaningrum, co-director of the Center on Child Protection at the University of Indonesia, is that only about half of Indonesian couples have been legally married, meaning that millions of couples with informal and ceremonial marriages will no longer be legally able to have sex.

“This law, when enforced, will immediately exclude the poor, the marginalized, people who live in remote places in the margins of public service,” she said.

While a ban on extramarital sex would be difficult, if not impossible, for the government to enforce, progressive activists fear it would empower local vigilantes to expose and extort cohabiting unmarried couples. This is already a fairly common practice in parts of Indonesia, although it lacks legal basis in much of the country.

In interviews, members of Indonesia’s conservative Islamist leadership say their side is ascendant. Hidayat Nur Wahid, former vice speaker of Indonesia’s parliament and a founder of the Prosperous Justice Party, an influential Islamist party, said he was confident that the law would be revised. He said that those who are not happy with such a decision should accept that the move would be democracy at work.

“What’s important is that decisions are made peacefully, in a way that isn’t forceful, in a way that’s rational,” he said. “This is democracy.”

Progressive activists see the court case as the latest sign that the democracy they fought for 18 years ago, after the fall of the authoritarian Suharto regime, will be used to impose a conservative vision of Islam on society.

“The progressive groups at some point were successful at providing the space for democracy, but we really could not make benefit from the open space,” said Tunggal, the women’s rights activist, who said uneven economic growth is leading Indonesians to embrace religious conservatism.

“All the institutions that support democracy are there,” she said, citing state commissions to protect the rights of women and to uphold human rights. “But on the ground, it’s kind of the opposite. There’s a gap — a kind of lack in skill and knowledge — on how to reach out to the grass roots.”

Ulil Abshar Abdalla, founder of the Liberal Islam Network, is one of the very rare Indonesian Islamic scholars to support gay rights. He said he is worried about the current legal case — as well as the overall direction in which his country is headed.

“Conservatism is becoming stronger and stronger,” he said. “The kind of Islam we are seeing today in Indonesia is changing a lot.”