Uganda's president signed a law imposing harsh penalties for homosexuality on Monday, defying protests from rights groups, criticism from Western donors and a U.S. warning that it will complicate relations.
The new bill strengthened existing punishments for anyone caught having gay sex, imposing jail terms of up to life for "aggravated homosexuality" - including sex with a minor or while HIV-positive.
It criminalised lesbianism for the first time and made it a crime to help individuals engage in homosexual acts. Gay rights activists in Uganda said they planned a legal challenge.
Ugandan officials broke into loud applause as President Yoweri Museveni put his signature to the document in front of foreign journalists at his State House outside the capital.
"There's now an attempt at social imperialism, to impose social values. We're sorry to see that you (the West) live the way you live but we keep quiet about it," he said.
The legislation exposes the wide gulf between the continent's often culturally conservative administrations and many of the foreign donor states that support them. Gambia's President Yahya Jammeh last week called homosexuals "vermin".
Western donors immediately criticised Uganda. Norway and Denmark said they were withholding or diverting aid money and Austria said it was reviewing assistance. Britain condemned the new law but did not mention aid cuts.
"I feel sick. The degrading words the president has used ... my country is in a state of insanity right now," said Ugandan gay activist Kasha Nabagesera, adding the gay community expected to challenge the bill in the courts.
Gay and lesbian organisations fear the bill will encourage other governments to strengthen penalties, increase harassment, discourage people from taking HIV tests and make it impossible to live an openly gay life.
"Disapproval of homosexuality by some can never justify violating the fundamental human rights of others," U.N. High Commissioner for Human Rights Navi Pillay said in a statement.
Homosexuality is taboo in almost all African countries and illegal in 37 - including Uganda, where rights groups say gay people have long risked jail. Fear of violence, imprisonment and loss of jobs means few gays in Africa come out.
U.S. Secretary of State John Kerry said it was a "tragic day for Uganda and for all who care about the cause of human rights," and that this "complicates a valued relationship."
He said in a statement the United States would review its relationship with Kampala "to ensure that all dimensions of our engagement, including assistance programs, uphold our anti-discrimination policies and principles and reflect our values."
Washington is one of Uganda's largest donors, sending more than $400 million a year.
Uganda is a key Western ally in the fight against Islamic extremism in Somalia, where Ugandan troops form the backbone of the African Union force battling al Qaeda-aligned militants.
British Foreign Secretary William Hague said on Monday London questioned the bill's compatibility with the Ugandan constitution and international treaty obligations. But he made no mention of aid cuts from Britain, another big donor.
Austria said it was reviewing its assistance. Denmark said it was diverting 50 million crowns of development aid away from the Ugandan government, and Norway said it would hold back 50 million krone of support.
"We cannot distance ourselves too strongly from the law and the signal that the Ugandan government now sends to not only persecuted minority groups, but to the whole world," Danish Trade and Development Minister Mogens Jensen said.
But analysts said any Western penalties could be tempered because Kampala was seen as a valuable regional ally, while Uganda expects to pump oil for the first time in 2016 and hopes the inflow of petrodollars will cut aid dependence.
"He knows that while the West cares about homosexuality, it's not to such an extent that they would severely punish a good ally," said Ugandan political analyst Angelo Izama.
A Ugandan government spokesman said Museveni had taken the unusual step of signing the bill in public to "demonstrate Uganda's independence in the face of Western pressure".
While African leaders broadly court Western donors with promises to tackle human rights abuses, many have won popular support by describing homosexuality as "un-African" behaviour.
The Uganda's move should please conservative voters ahead of presidential elections scheduled for 2016.
"We don't like (homosexuality) in our culture," said motorbike taxi driver Ronald Kibabu. "That can keep him as president. The election is coming."
Museveni said last week he was putting the bill on hold to give scientists a chance to prove that homosexuality could be triggered by genes and was not a "lifestyle choice". They found no such evidence, Museveni said.
In neighbouring Kenya, a group of MPs has called for the enforcement of existing anti-gay laws that have been largely ignored. Some Kenyans praised Uganda's actions.
"kudos to #Museveni for refusing to bow to #Obama demands on the homosexuality law," said Kenyan Twitter user @Chabbuh.