Deputies voted overwhelmingly in favour of the text, which has been widely condemned by rights activists and world leaders -- with US President Barack Obama describing it as "odious" and Nobel Peace laureate Desmond Tutu comparing it to apartheid.
The lawmaker behind the bill, David Bahati, said a death penalty clause was dropped from the final version. The approved text must now be given the green light by President Yoweri Museveni, a devout evangelical Christian.
"This is a victory for Uganda. I am glad the parliament has voted against evil," Bahati told AFP.
"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."
First proposed in 2009, the bill had been shelved following international condemnation, but parliamentary spokeswoman Hellen Kaweesa said the changes meant it had secured "majority support" among MPs.
"Now anybody found practising, recruiting for or publicising homosexuality commits a felony," said Minister of State for Ethics and Integrity Simon Lokodo.
He added that the law provided for punishments of between two years and life behind bars.
An early version of the bill would have introduced the death sentence for anyone caught engaging in homosexual acts for a second time, as well as for gay sex where one partner is a minor or has HIV.
"We will get hold of all those encouraging others to become homosexuals or lesbians. Anybody we find recruiting or using materials to promote homosexuality, we will arrest," said Lokodo.
Homophobia is widespread in Uganda, where American-style evangelical Christianity is on the rise. Gay men and women in the country face frequent harassment and threats of violence, and rights activists have also reported cases of lesbians being subjected to "corrective" rapes.
In 2011, prominent Ugandan gay rights activist David Kato was bludgeoned to death at his home after a newspaper splashed photos, names and addresses of gays in Uganda on its front page along with a yellow banner reading "Hang Them".
A British man, Bernard Randall, is currently facing trial in Uganda and a possible two-year sentence if convicted for "trafficking obscene publications" after police found pictures of him having gay sex.
While homosexuality was already illegal, the new bill increases penalties and also criminalises the public promotion of homosexuality -- including discussions by rights groups.
After the vote, Ugandan gay activist Frank Mugisha declared himself "officially illegal" and also "outraged and disappointed".
"This is a truly terrifying day for human rights in Uganda," he said.
The European Union's diplomatic chief, Catherine Ashton, said the bill violated international human-rights charters to which Uganda was party.
"I urge the Ugandan authorities to ensure respect of the principle of non-discrimination, guaranteed in the Ugandan constitution, and to preserve a climate of tolerance for all minorities in Uganda," she said.
Leslie Lefkow of Human Rights Watch said the law was "abhorrent", and Amnesty International said the "wildly discriminatory legislation" was "a grave assault on human rights".
One Ugandan MP, Fox Odoi, was also critical.
"Fundamentally there is the human rights issue. It's a bad law and it doesn't serve any useful purpose," he said.
The vote came a day after the Ugandan parliament passed an anti-pornography and dress-code law banning anything deemed sexually suggestive.
In 2008, former ethics and integrity minister James Nsaba Buturo tried to pass similar legislation claiming a woman wearing provocative clothing risked causing traffic accidents by distracting drivers.
President Museveni caused an uproar in 2012 when he told female school students to "keep a padlock on your private parts until the time comes to open them when you have a husband".
In addition to outlawing "provocative" clothing, the anti-pornography bill will ban scantily dressed performers from Ugandan television and closely monitor what individuals watch on the Internet.
By Grace Matsiko