The president of Uganda signed a punitive anti-gay bill on Monday that includes the death penalty, enshrining into law an intensifying crackdown against L.G.B.T.Q. people in the conservative East African nation and dismissing widespread calls not to impose one of the world’s most restrictive anti-gay measures.
The law, which was introduced in Parliament in March, calls for life imprisonment for anyone who engages in gay sex. Anyone who tries to have same-sex relations could be liable for up to a decade in prison.
The law also decrees the death penalty for anyone convicted of “aggravated homosexuality,” a term defined as acts of same-sex relations with children or disabled people, those carried out under threat or while someone is unconscious. The offense of “attempted aggravated homosexuality” carries a sentence of up to 14 years.
The legislation is a major blow to efforts by the United Nations, Western governments and civil society groups that had implored the president, Yoweri Museveni, not to sign it.
Karine Jean-Pierre, the White House press secretary, has said the bill would “damage Uganda’s international reputation.”
But Mr. Museveni was unmoved, saying in a video released by the state broadcaster in April that the country had “rejected the pressure from the imperials,” a reference to Western nations.
On Monday, the speaker of Uganda’s Parliament, Anita Annet Among, first announced on Twitter that the president had signed the bill into law. “I thank my colleagues the Members of Parliament for withstanding all the pressure from bullies and doomsday conspiracy theorists in the interest of our country,” she said.
The law, activists said, tramples the rights of L.G.B.T.Q. people and leaves them vulnerable to discrimination and violence. Homosexuality is already illegal in Uganda, but the new law calls for far more stringent punishment and broadens the list of offenses.
The law’s passage has stoked fear among L.G.B.T.Q. people, many of whom have begun fleeing Uganda. Gay rights groups say hundreds of gay people — facing rejection from their families, discrimination at work or mob justice in the streets — have reached out to them in recent weeks seeking help.
“There’s fear that this law will embolden many Ugandans to take the law into their hands,” said Frank Mugisha, the most prominent openly gay rights activist in Uganda. “This law will put so many people at risk. And that creates anxiety and fear.”
The legislation also represents a major victory for many of the country’s religious groups, whose members had organized street protests urging lawmakers to protect children and what they portrayed as the sanctity of the traditional African family.
The Rev. Stephen Samuel Kaziimba, the archbishop of the Church of Uganda, said in February that gay groups were “recruiting our children into homosexuality.”
The sweeping anti-gay measure comes as a growing number of African countries — including Kenya and Ghana — consider passing similar or even stricter legislation.
The Ugandan legislation, known officially as the Anti-Homosexuality Act, was first passed by Parliament in March. But instead of signing it immediately, Mr. Museveni sent it back for amendments, seeking to make clear a distinction between being gay and engaging in gay sex.
Lawmakers did add language making clear that anyone suspected of being a homosexual would not be punished unless they engaged in same-sex relations, before adopting the bill again.
The rest of the law remained the same, including mandating a prison term of up to 20 years for anyone who promotes homosexuality, a vague provision that activists fear could be used to target agencies supporting L.G.B.T.Q. people, including those providing lifesaving AIDS treatment.
Anyone younger than 18 convicted of having gay sex faces up to three years in prison. The law, which also encourages the public to report any suspected acts of homosexuality, contains ambiguous language that makes it difficult to interpret.
Anyone who allows premises to be used for same-sex relations could face up to seven years in prison and a person convicted of homosexuality could be sent for “rehabilitation.”
A team of lawyers and activists is drafting a lawsuit, whose details have not been divulged, challenging the law in Uganda’s Constitutional Court.
The legislation follows a yearslong campaign in Uganda to criminalize L.G.B.T.Q. people and those who support them. Politicians first drew up a similar measure in 2009, but when it was signed into law in 2014, the court struck it down on procedural grounds.
But over the past few years, political leaders, along with domestic and international religious organizations, began ramping up anti-gay campaigns and warning about what they call a threat to family values.
Politicians also began making baseless claims about a plot to promote gay activities and lure children in schools to homosexuality. Last year, the authorities shut down Sexual Minorities Uganda, a leading gay rights advocacy group, claiming it had not been officially registered with the government.
“What’s so troubling about this moment is how swiftly the bill moved through Parliament and how thoroughly Uganda’s institutions beyond the legislature, like the judiciary and police, have absorbed and pushed anti-L.G.B.T.Q. sentiment,” said Gillian Kane, a senior analyst at Ipas, a nonprofit, who has studied anti-gay measures across Africa.
The swift passage of the Ugandan bill, she added, was partly driven by the support it received from organizations outside the country.
Those include Family Watch International, an Arizona-based organization that promotes the bogus practice of conversion therapy to change someone’s sexual orientation. Just days after the bill was first passed in March, the organization’s American founders helped organize a conference in Uganda among African lawmakers to promote anti-gay measures continentwide.
“The passage of this bill has implications beyond L.G.B.T.Q. rights,” Ms. Kane said. “By trampling on human rights and constitutional law, this bill is a political project for authoritarianism.”
Some analysts said the law was meant to scapegoat gay people and distract the public from mounting domestic challenges, including rising unemployment and skyrocketing food prices. Mr. Museveni, who has been in power for almost four decades, has also faced increased scrutiny for his crackdown on the opposition and human rights activists.
“Homosexuality remains highly politicized in Uganda,” said Helen Epstein, the author of a book exploring the president’s long hold on power. “It is very much a product of Museveni’s malevolent political genius.”