The new law appears to be the first to outlaw merely identifying as lesbian, gay, bisexual, transgender and queer (LGBTQ), according to rights group Human Rights Watch.
"The ayes have it," parliamentary speaker Annet Anita Among said after a final vote, adding that the "bill passed in record time."
In addition to same-sex intercourse, the law bans promoting and abetting homosexuality as well as conspiracy to engage in homosexuality.
Supporters of the new law say it is needed to punish a broader array of LGBTQ activities, which they say threaten traditional values in the conservative and religious East African nation.
Violations under the law draw steep penalties including death for so called aggravated homosexuality and life in prison for gay sex. Aggravated homosexuality involves gay sex with people under 18 years old or when the perpetrator is HIV positive, among other categories, according to the law.
"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 legislation will be sent to President Yoweri Museveni to be signed into law.
Museveni has not commented on the current proposal but he has long opposed LGBTQ rights and signed an anti-LGBTQ law in 2013 that Western countries condemned before a domestic court struck it down on procedural grounds.
In recent weeks, Ugandan authorities have cracked down on LGBTQ individuals after religious leaders and politicians alleged students were being recruited into homosexuality in schools.
More than 30 African countries, including Uganda, already ban same-sex relations.