JAKARTA, Indonesia — Prodded by religious conservatives, Indonesia is moving toward outlawing gay sex — and even sex outside marriage — in a jarring change for a country long seen as a bastion of tolerance in the Islamic world.

The proposed sexual crackdown in the Southeast Asian archipelago of more than 260 million people — the world’s largest Muslim-majority nation and third-largest democracy — is drawing criticism at home and abroad from human rights organizations and LGBT activists. They warn that penal-code revisions now under consideration in parliament would discriminate against large numbers of people, promote extremist views and reverse democratic gains.

Ichsan Soelistio, a member of a special commission in the Indonesian House of Representatives working to update the country’s criminal code, said the body has reached consensus to include laws outlawing extramarital sex as well as gay sex, and is likely to do so soon but with some limitations.

“More-conservative elements want full criminalization, which we reject,” Soelistio, a member of Indonesia’s largest political party, said in an interview this week. “But we have agreed to accept a law which allows prosecution of sex outside marriage and homosexual sex, but only if one of the sexual partners or their family members report the crime to police.”

President Joko Widodo, a fellow member of Soelistio’s Indonesian Democratic Party of Struggle, is considered more secular and liberal than most major Indonesian politicians, and he almost certainly will face off against a more conservative Muslim figure in his bid for reelection in April next year. The legislators also face reelection, and opposition parties recently have used religion as a wedge issue to great effect.

In the interview in his parliamentary office, Soelistio, 63, repeatedly emphasized that his party would prefer to stay out of regulating citizens’ private lives. But he asserted that given political realities, the proposed new rules were the best way to protect LGBT and other at-risk communities.

“Without this kind of firewall, there is the risk that the public can try to take the law into their own hands,” he said. “We are not banning gay people. We are trying to give them freedom within certain limits.”

Not everyone finds this argument convincing.

“That is not protection,” said Lini, an Indonesian LGBT activist. “LGBT Indonesians are often rejected by their families or the victims of violence within the family. Allowing their parents to throw them in jail legally is the opposite of helping.” Lini, who works with the LGBT organization Arus Pelangi (Rainbow Flow), did not want to be identified by her full name out of fear for her safety.

She said she has been shocked by how quickly political sentiment has shifted on the issue: “Six months ago, I would have thought it very unlikely a law like this would actually be passed. Now we have little reason to feel optimistic.”

On a visit to Jakarta this week, U.N. High Commissioner for Human Rights Zeid Raad al-Hussein came to a similar conclusion.

“I am greatly concerned about the discussions around revisions to the penal code,” the former Jordanian diplomat said at a news conference. “These discussions betray strains of intolerance seemingly alien to Indonesian culture. . . . The extremist views playing out in the political arena are deeply worrying, accompanied as they are by rising levels of incitement to discrimination, hatred or violence in various parts of the country.”

Hussein urged Indonesians to consolidate their democracy by moving “forward — not backward — on human rights.” He added: “Because these proposed amendments will in effect criminalize large sections of the poor and marginalized, they are inherently discriminatory. LGBTI Indonesians already face increasing stigma, threats and intimidation. The hateful rhetoric against this community that is being cultivated seemingly for cynical political purposes will only deepen their suffering and create unnecessary divisions. (LGBTI stands for lesbian, gay, bisexual, transgender and intersex.)

In cases of gay sex, the proposed changes call for prison sentences for acts committed in public, with a minor or when used for commercial or pornographic purposes. In such cases, a complaint by one partner or family member is not required.

Police began using existing pornography laws last year to crack down on gay parties, as the country’s politics took an apparent turn toward increased religious conservatism.

Widodo ally Basuki Tjahaja Purnama, a Christian of Chinese descent commonly known as “Ahok, lost his bid for reelection as Jakarta governor last April, then was jailed for comments he made during his campaign that were deemed blasphemous to Islam.

The episode, which included mass protests organized by Islamist groups, put Widodo’s party on the defensive and convinced many politicians that a moral crusade could be a cheap and easy way to appeal to voters, analysts said.

“For several decades, the perceived importance of religious identity and piety among Indonesian Muslims has been growing,” said David Henley, professor of contemporary Indonesia studies at Leiden University in the Netherlands. This is partly because of globalization and contact with more-conservative Islamic societies elsewhere — and partly a reaction to increasing urbanization and modernization, he added.

On Thursday, a group of female Indonesian activists presented an online petition to lawmakers and asked them to abandon the penal-code revisions, but they reported on social media that the meeting was frustrating.

Indonesians who do not want to see the state add tools to regulate private sexuality hope that international pressure prompts the government to change tack, or that proponents of the changes simply fail to get them through the legislature. Indonesia’s criminal code has not been updated since the archipelago was ruled as a Dutch colony before World War II.

“This time, however, they are really determined to get this done and may do so as soon as next month,” said Maidina Rahmawati, a researcher at Indonesia’s Institute for Criminal Justice Reform. “They want to present it as a major achievement.”

The reason for expanding sexual crimes is simple, she said: “In contemporary Indonesian politics, religion and morality have proven to be effective weapons.”