More than 30 African countries, including Uganda, already ban same-sex relations.
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.
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.
In addition to same-sex intercourse, the law bans promoting and abetting homosexuality as well as conspiracy to engage in homosexuality.
I support the bill to protect the future of our children," lawmaker David Bahati said during debate on the bill.
"This law is very extreme and draconian ... it criminalises being an LGBTQ person, but also they are trying to erase the entire existence of any LGBTQ Ugandan," he said.
In recent weeks, Uganda authorities have cracked down on LGBTQ people after religious leaders and politicians alleged students were being recruited into homosexuality in schools. »