The bill, passed last month, calls for life in prison for anyone engaging in same-sex relations. President Yoweri Museveni congratulated lawmakers for their “strong stand” against L.G.B.T.Q. people.
In a spartan safehouse with flimsy curtains and no furniture northwest of the Kenyan capital, Nairobi, people from neighboring Uganda clung to the few valuables they could snatch while fleeing harsh new legislation targeting them back home.
A gay man clutched the white rosary that he took to church every Sunday. A transgender woman brought her favorite shimmering blue dress. A lesbian couple clenched the one smartphone that held photos from happier days, going on dates and dancing in clubs.
They began leaving after Uganda’s Parliament passed a sweeping anti-gay bill in late March that threatens punishment as severe as death for some perceived offenses, and calls for life in prison for anyone engaging in same-sex relations.
“The government and the people of Uganda are against our existence,” said Mbajjwe Nimiro Wilson, a 24-year-old who fled with a single backpack days after a hostile crowd, including children, cornered him as he bought groceries near a gay shelter in the capital, Kampala.
“They kept saying, ‘We will hunt you. You gays should be killed. We will slaughter you,’” he said. “There was no option but to leave.”
The bill, which passed 387 to 2, punishes anyone who leases property to gay people and calls for the “rehabilitation” of those convicted of being gay. President Yoweri Museveni has commended the bill, though he sent it back to Parliament on Thursday for “improvement,” his party said in a statement.
The president congratulated lawmakers and religious leaders on what he called their “strong stand” against L.G.B.T.Q. people. “It is good that you rejected the pressure from the imperials,” he said, a reference to Western countries, in footage released by the public broadcaster.
The legislation follows a groundswell of anti-gay rhetoric that has swept African countries in recent years, including in Ghana, Zambia and Kenya. Last month, lawmakers from more than a dozen African countries gathered in Uganda and promised to introduce or pass measures in their own countries that they said would protect the sanctity of the family and children against “the sin of homosexuality.”
Same-sex acts were already considered illegal under Uganda’s penal code, but the bill introduces far harsher penalties and vastly extends the range of perceived offenses. And while anti-gay rhetoric has long existed in Uganda, it has taken a severe turn in the past year, with authorities removing rainbow colors from a park and parents charging into a school because they thought a gay person taught there.
The latest move to target L.G.B.T.Q. people in Uganda has drawn support from local Christian and Muslim groups, and for years the financial and logistical backing of some conservative evangelical groups in the United States. One of the key organizers of the parliamentary conference in Uganda last month was Family Watch International, an Arizona-based organization that spreads anti-L.G.B.T.Q. and anti-abortion stances, according to the Southern Poverty Law Center.
The Ugandan bill has drawn condemnation from human rights groups and the United Nations, and the Biden administration has called it “one of the most extreme” anti-gay measures anywhere in the world.
Senator Bob Menendez, Democrat of New Jersey, said the United States should reduce military aid and introduce sanctions against the government of Mr. Museveni, who has been in power for almost four decades. The East African nation, a close security ally of the United States, receives more than $950 million annually in health and development assistance.
After months of campaigning against it, gay rights activists in Uganda are now planning to challenge the measure in court if it is signed.
“What this law does is give homophobia a legal basis and framework,” said Fox Odoi-Oywelowo, a former senior counsel to Mr. Museveni, and one of two lawmakers who opposed it. Many lawmakers mocked Mr. Odoi-Oywelowo, accusing him of receiving money to promote what they said was an immorality of the West.
He plans to join the legal challenge against the bill. “If the state chooses for a human being who to fall in love with,” he said, “that would be the greatest abrogation of our most basic rights.”
For L.G.B.T.Q. Ugandans, the bill is set to further formalize the widespread discrimination that many felt daily. In interviews, more than a dozen gay Ugandans who had fled to Kenya described how their friends, family and neighbors turned against them over the past year, as renewed anti-gay sentiment swept over the conservative nation.
In Parliament, lawmakers promoted the baseless allegation that there was a plot to promote homosexuality in schools. Officials vilified gay people on television and social media, and one military official said they should be denied medical care. In the streets, Muslims marched against them, and in Christian churches, clerics urged congregants to remain watchful about efforts to lure their children into homosexuality.
Last August, the authorities took their most drastic action yet when they closed Sexual Minorities Uganda, the country’s leading gay rights group.
After Parliament adopted the bill in March, dozens of L.G.B.T.Q. people began fleeing to neighboring Kenya, their advocates said, because of the proximity and the presence of a strong human rights network.
Those who fled include Oboza James, a 23-year-old transgender woman who for years faced rejection and abuse from her family. But last year, she found refuge and community at a shelter in Nansana, in central Uganda. That lasted until September, when three men and a woman, whom she believes came from her family’s neighborhood in Kampala, cornered her on a street and beat her up.
“They kept saying, ‘You are a disgrace,’” Ms. James remembered during an interview in Nakuru, Kenya. As they kicked and punched her, she said, “I thought I was going to die.”
Among the provisions of Uganda’s anti-gay bill is the prohibition of what it calls the “promotion” of homosexuality. Lawyers said the clause could put activists and aid agencies supporting gay rights at risk of criminal liability.
These could include American-funded health programs supporting L.G.B.T.Q. people who had come under scrutiny and attack when Uganda enacted similar laws that courts struck down in 2014.
In a statement, a State Department spokesman said if the bill were ratified, it would leave the funding for Pepfar, the American program that delivers H.I.V. treatment to millions, “severely compromised.” It would also “jeopardize” Uganda’s progress toward ending AIDS as a public health threat by 2030, the statement said.
The Ugandan bill is already inspiring others across the continent, including in Kenya, where a recent Supreme Court decision had allowed gay rights groups to register legally — a ruling that has drawn vocal criticism from the president and others.
Because of that, one lawmaker has introduced legislation similar to Uganda’s that would criminalize homosexuality, banning anyone from identifying as L.G.B.T.Q. and giving the public the power to arrest anyone they suspect of being gay. The bill would also prohibit the teaching of reproductive health and rights in schools.
“These people are perverts and I promise I will legislate to take every right they think they have,” George Peter Kaluma, the Kenyan lawmaker, said in an interview.
Mr. Kaluma said his bill would also include returning sexually persecuted refugees, many of whom are dispersed in camps across Kenya, to their countries. Without evidence, he accused U.S. Democrats and the Biden administration of funding them to promote homosexuality in Kenya. He also vowed that similar laws would soon extend across Africa.
“It is going to spread like a whirlwind,” he said.
That warning has sown fear among L.G.B.T.Q. Ugandans, who said they felt a sigh of relief when they first crossed into Kenya. Many of them are already thinking about where to go next.
For now, at the Nakuru safehouse, they gather to cook a meal or watch a movie in the evening. Many remain glued to their phones, reading news about the bill or reminiscing about happier moments back home.
Sometimes they make new connections, too — as when the sound notification of the dating app Grindr recently buzzed on Mr. Wilson’s phone. Even though he smiled and said he would chat with the person, it was unlikely they would ever meet, he said.
“It is better to remain indoors and not risk it,” he said. “We are not safe anywhere.”
Musinguzi Blanshe contributed reporting from Kampala, Uganda, and John Eligon from Johannesburg.