Updated

Uganda's president signed an anti-gay bill Monday that provides for prison sentences ranging up to life behind bars, saying it is needed because the West is promoting homosexuality in Africa. Arrests of gays were expected as a result, one politician said.

The new law goes into effect immediately and calls for first-time offenders to be sentenced to 14 years in jail. It sets life imprisonment as the maximum penalty for "aggravated homosexuality," defined as repeated gay sex between consenting adults and acts involving a minor, a disabled person or where one partner is infected with HIV.

U.N. High Commissioner for Human Rights Navi Pillay warned that the law would institutionalize discrimination and could encourage harassment and violence against gays.

The law is expected to send the country's beleaguered gay community further underground as the police try to implement it amid fevered anti-gay sentiment. At least six people have already been arrested over alleged homosexual offenses and more than a dozen have fled Uganda since lawmakers passed the bill in December, according to a prominent Ugandan gay activist, Pepe Julian Onziema.

"The president is making this decision because he has never met an openly gay person. That disappoints me," he said.

President Yoweri Museveni signed the bill at the presidential palace as government officials, journalists and Ugandan scientists looked on. Government officials applauded after Museveni affixed his signature. The scientists had written a report which found there is no proven genetic basis for homosexuality, and which was cited by Museveni in backing the bill, claiming it disproved that people can be born homosexual.

Some European countries have threatened to cut aid to Uganda if the measure was enacted. U.S. President Barack Obama warned that signing the bill would "complicate" the East African country's relationship with Washington.

But in signing the legislation passed by Parliament, Museveni rejected such reaction as interference in Ugandan affairs. A similar measure signed into law recently in Nigeria by its president.

"We Africans never seek to impose our view on others. If only they could let us alone," Museveni said. "We have been disappointed for a long time by the conduct of the West. There is now an attempt at social imperialism."

Museveni accused "arrogant and careless Western groups" of trying to recruit Ugandan children into homosexuality, but he did not name these purported groups.

Museveni said he believes Western homosexuals have targeted poor Ugandans who then "prostitute" themselves for the money, an allegation repeated by the bill's Ugandan defenders. Museveni did not cite any examples of people he called "mercenary homosexuals."

Some critics believe Museveni signed the bill in hopes of galvanizing political support within his party, the National Resistance Movement, ahead of an upcoming meeting that is expected to endorse him as the party's sole choice in the 2016 presidential election.

Fox Odoi, a Ugandan lawmaker who was once Museveni's legal adviser and the only legislator who publicly opposed the anti-gay measure, predicted more arrests over alleged homosexual offenses now that the bill is law.

"I find it utterly primitive," he said. "But the president doesn't think so. It is a very dark day for the gay community. It is going to result in big harassment of gay people."

The bill in its original draft called for the death penalty for some homosexual acts. That penalty was removed from the legislation following an international outcry.

The bill is widely popular in Uganda, where it has been championed by Christian clerics and many politicians.  Ugandan schoolchildren from various schools in the capital, Kampala, celebrated after Museveni signed the bill. With big smiles on their faces and arms stretched in jubilation, they held placards including one that said "Obama leave us alone: Homosexuals have no room in Uganda."

The anti-gay measure was introduced in 2009 by a lawmaker with the ruling party who said the law was necessary to deter Western homosexuals from "recruiting" Ugandan children.

That legislator, David Bahati, said Monday that the bill's enactment is "a triumph of our sovereignty, a victory for the people of Uganda, the children of Uganda."

Several Ugandan gays say Bahati and other political leaders were influenced by conservative U.S. evangelicals who wanted to spread their anti-gay agenda in Africa.