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 dropped.
The bill bans the promotion of homosexuality.
"I am officially illegal," Ugandan gay activist Frank Mugisha said after the vote.
Human rights activists say the bill highlights the intolerance and discrimination the gay community faces in Ugandahttp://www.bbc.co.uk/news/world-africa-25463942