The bill was passed late on Tuesday inside a packed parliamentary chamber, and was supported by nearly all of the 389 legislators present.
It was introduced last month by an opposition lawmaker who said his goal was to punish “promotion, recruitment and funding” related to LGBT+ activities.
His bill creates the offence of “aggravated homosexuality”, which applies in cases of sex relations involving those infected with HIV, as well as minors and other categories of vulnerable people.
It was not immediately clear what the punishment is for that offence following last-minute amendments in a protracted session in the Uganda capital, Kampala.
"Our creator God is happy (about) what is happening... I support the bill to protect the future of our children," said lawmaker David Bahati during debate on the bill. "This is about the sovereignty of our nation, nobody should blackmail us, nobody should intimidate us."
The bill also creates the offence of “attempted homosexuality”, punishable with up to 10 years in jail.
Same-sex activity is already punishable with life imprisonment under a colonial-era law targeting “carnal knowledge against the order of nature".
The bill is “ill-conceived” and unconstitutional because it “criminalises individuals instead of conduct,” said lawmaker Fox Odoi, representing the dissenters.
The House speaker had repeatedly warned it was necessary to identify those who might oppose the bill.
The bill, if signed into law, “would violate multiple fundamental rights, including rights to freedom of expression and association, privacy, equality, and non-discrimination," according to Human Rights Watch. “One of the most extreme features of this new bill is that it criminalises people simply for being who they are as well as further infringing on the rights to privacy, and freedoms of expression and association that are already compromised in Uganda,” the group’s Oryem Nyeko said in a statement earlier this month.
“Ugandan politicians should focus on passing laws that protect vulnerable minorities and affirm fundamental rights and stop targeting LGBT+ people for political capital.”
Uganda’s LGBT+ community in recent years has faced pressure from civilian authorities who wanted a tough new law punishing same-sex activity.
The bill now will go to President Yoweri Museveni, who can veto or sign it into law.
He suggested in a recent speech that he supports the bill, accusing unnamed Western nations of “trying to impose their practices on other people.”
Want a quick and expert briefing on the biggest news stories? Listen to our latest podcasts to find out What You Need To Know