Ugandan politicians have passed an anti-gay law that punishes "aggravated homosexuality" with life imprisonment.

The bill drew wide condemnation when it was first introduced in 2010 and included the death penalty, but that was removed from the revised version passed by parliament.

Although a provision for the death penalty was removed from the original bill, the law passed on Friday sets life imprisonment as the maximum penalty for the new offence of "aggravated homosexuality" – repeat offending – according to the office of a spokeswoman for Uganda's parliament.

Homosexuality was already illegal in Uganda under a colonial-era law that criminalised sexual acts "against the order of nature", but the Ugandan politician who wrote the new law argued that tough new legislation was needed because gay people from the west threatened to destroy Ugandan families and were allegedly "recruiting" Ugandan children into gay lifestyles.

The Ugandan gay community has disputed this account, saying that Ugandan political and religious leaders had come under the influence of American evangelicals who wanted to spread their anti-gay campaign in Africa. They have singled out Scott Lively, a Massachusetts evangelical, who they sued in March 2012 under the Alien Tort Statute that allows non-citizens to file suit in the US if there is an alleged violation of international law.

Lively denied he wanted severe punishment for gay people, and has previously said he never advocated violence against gay people but advised therapy for them.

Over the years gay people in Uganda had come to believe progress was being made in defence of their rights in a country where homophobia is rampant. In 2012 they held their first gay pride parade and have sometimes joined street marches in support of all human rights.

Pepe Julian Onziema, a prominent Ugandan transgender and gay activist, declined to comment when contacted on Friday, saying he needed more time.

Despite criticism of the bill abroad, it was highly popular among a lot of Ugandans who said the country had the right to pass laws that protect its children.

Amid international criticism, the bill was repeatedly shelved despite the protests of Ugandan politicians. Days before Christmas last year, the speaker of Uganda's parliament, Rebecca Kadaga, threatened to pass the anti-gay law as a "Christmas gift" to all Ugandans.

When the bill was first proposed, Barack Obama called it "odious".