Uganda's parliament has passed a bill to toughen the punishment for homosexual acts to include life imprisonment in some cases.
The anti-homosexuality bill also makes it a crime punishable by a prison sentence not to report gay people.
The prime minister opposed the vote, saying not enough MPs were present.
The bill has been condemned by world leaders since it was mooted in 2009 - US President Barack Obama called it "odious".
The BBC's Catherine Byaruhanga in Kampala says the government knows there will be an international outcry, which could see some countries suspend aid to the country.
She says that Prime Minister Amama Mbabazi might follow up on his complaints about a lack of quorum, while it remains to be seen whether President Yoweri Museveni will sign the bill into law.
The private member's bill originally proposed the death penalty for some offences, such as if a minor was involved or the perpetrator was HIV-positive, but this has been replaced with life in prison.
The MP behind the bill, David Bahati, told the AFP news agency: "This is victory for Uganda. I am glad the parliament has voted against evil."
"Because we are a God-fearing nation, we value life in a holistic way. It is because of those values that members of parliament passed this bill regardless of what the outside world thinks," he said.
The bill also bans the promotion of homosexuality.
"I am officially illegal," Ugandan gay activist Frank Mugisha said after the vote.
The bill's supporters say it is needed to protect traditional family values, which they say are under attack from Western-inspired gay rights groups.
Its critics say the bill has been pushed by some US evangelical Christians.
Uganda is a socially conservative country and on Thursday passed an Anti-Pornography Bill, which bans miniskirts and sexually suggestive material such as some music videos.
Human rights activists say the bill highlights the intolerance and discrimination the gay community faces in Uganda.
One gay activist was killed in 2011, although the police denied he was targeted because of his sexuality.
Meanwhile a local newspaper has been condemned for publishing the names and addresses of people it said were gay.
Holidaymakers and visiting foreigners are not immune from prosecution under Uganda's existing anti-homosexuality laws.
A retired British man is awaiting trial in Entebbe on charges of possessing a gay sex video after thieves found images on his laptop.
Sixty-five-year-old Bernard Randall, from Kent, faces a possible two-year prison sentence if found guilty.
His friend Albert Cheptoyek, a Ugandan national with whom he shares a house, has denied a more serious charge of carrying out "acts of gross indecency", which could see him jailed for up to seven years if found guilty.