What you need to know:
- The bill will now be sent to Museveni, who can again choose to use his veto or sign it into law.
Uganda's parliament on Tuesday passed a new draft of anti-gay legislation, retaining many tough provisions despite President Museveni's call to rework an earlier version of the bill following outcry from Western governments.
"The bill passed," parliamentary Speaker Annet Anita Among said after the final vote saw the legislation win approval from all but one lawmaker.
"We have a culture to protect. The Western world will not come to rule Uganda," she said.
Legislators amended portions of the draft law to clarify that identifying as gay would not be criminalised, but "engaging in acts of homosexuality" would be an offence punishable with life imprisonment.
Although Museveni had advised lawmakers to delete a provision making "aggravated homosexuality" a capital offence, lawmakers rejected that move, meaning that repeat offenders could be sentenced to death.
Uganda has not resorted to capital punishment for many years.
'Conflicts in society'
The revamped bill says that "a person who is believed or alleged or suspected of being a homosexual, who has not committed a sexual act with another person of the same sex, does not commit the offence of homosexuality".
Lawmakers agreed to amend that provision on Tuesday after Museveni last month said it risked creating "conflicts in society."
Instead, the reporting requirement now pertains only to suspected sexual offences against children and vulnerable people, with the penalty raised to five years in jail.
According to the new draft, anyone who "knowingly promotes homosexuality" faces up to 20 years in jail -- a provision left unchanged from the original bill.
Organisations found guilty of encouraging same-sex activity could face a 10-year ban.
Frank Mugisha, executive director of Sexual Minorities Uganda, a leading gay rights organisation whose operations were suspended by the authorities last year, said the passage of the bill posed a grave risk to LGBTQ people.
"There's a contradiction because the legislation says you can be gay but you shouldn't say anything about it," he told AFP.
Furthermore, the near-unanimous approval of the bill by lawmakers "shows you how extreme and homophobic the MPs are and puts LGBTQ people in even more danger."
The bill will now be sent to Museveni, who can again choose to use his veto or sign it into law.
If he were to return the bill to parliament a third time, a two-thirds super-majority of lawmakers could override his veto, forcing the bill through.
The legislation enjoys broad public support in Uganda and reaction from civil society has been muted following years of erosion of civic space under Museveni's increasingly authoritarian rule.
The European Parliament last month voted to condemn the bill and asked EU states to pressure Museveni into not implementing it, warning that relations with Kampala were at stake.
The White House has also warned the Ugandan government of possible economic repercussions if the legislation takes effect.
Last week the US embassy wrote to delegates working on funding proposals to tackle the AIDS epidemic informing them of delays "in light of the recent developments with the potential signing of the Anti-Homosexuality Act and how it could impact our ability to provide services and assistance".
Homosexuality was criminalised in Uganda under colonial laws, but there has never been a conviction for consensual same-sex activity since independence from Britain in 1962.