Ugandan President Yoweri Museveni said the bill, which goes into effect immediately, was needed because the West is promoting homosexuality in Africa.
Yoweri Museveni may have defied Western pressure to shelve the bill, four years and many versions after it was introduced, but his move - likely to galvanize support ahead of presidential elections - pleased many Ugandans who repeatedly urged him to sign the legislation.
Nigeria's president similarly signed an anti-gay bill into law just over a month ago, sparking increased violence against gays who already were persecuted in mob attacks. Some watchdog groups warn a similar backlash of violence may occur in Uganda.
"Experience from other jurisdictions with similarly draconian laws, such as Nigeria or Russia, indicates that their implementation is often followed by a surge in violence against individuals thought to be lesbian, gay, bisexual or transgender,'' the International Gay and Lesbian Human Rights Commission said in a statement Monday. "The Ugandan government has not indicated any plans to counter such violence or to investigate potential allegations of abuse.''
The Ugandan law 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.
Uganda's new anti-gay law has been condemned around the world.
In Washington, White House press secretary Jay Carney called the law "abhorrent,'' urged its repeal and said the White House is reviewing its relationship with Uganda.
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 office of European Union foreign policy chief Catherine Ashton in a statement said she is "is deeply concerned'' by "draconian legislation'' to criminalize homosexuality in Uganda.
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.
Yoweri Museveni signed the bill at the presidential palace as government officials, journalists and Ugandan scientists looked on. Government officials applauded after Yoweri Museveni affixed his signature. Scientists had written a report which found there is no proven genetic basis for homosexuality, Yoweri Museveni said, citing it as a reason for signing the bill.
"They should rehabilitate themselves and society should assist them to do so,'' Yoweri Museveni said after signing the bill.
Some European countries have threatened to cut aid to Uganda if the measure was enacted, though some EU officials have cautioned that interrupting development aid may not be the best reaction since it would harm Ugandans.
U.S. President Barack Obama warned that signing the bill would "complicate'' the East African country's relationship with Washington. After Yoweri Museveni signed the bill, the White House said the U.S. would urge Uganda's government to repeal the "abhorrent law.''
"As President Obama has said, this law is more than an affront and a danger to the gay community in Uganda, it reflects poorly on the country's commitment to protecting the human rights of its people and will undermine public health, including efforts to fight HIV/AIDS,'' the statement said.
But in signing the legislation passed by lawmakers, Yoweri Museveni said he rejected such reaction as interference in Ugandan affairs.
"We Africans never seek to impose our view on others. If only they could let us alone,'' Yoweri Museveni said. "We have been disappointed for a long time by the conduct of the West. There is now an attempt at social imperialism.''
Yoweri Museveni accused "arrogant and careless Western groups'' of trying to recruit Ugandan children into homosexuality, but he did not name these purported groups.
Yoweri 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. Yoweri Museveni did not cite any examples of people he called "mercenary homosexuals.''
Some critics believe Yoweri 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 Yoweri 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 Yoweri 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.
Homosexuality is criminalized in many African countries.