Uganda’s president has signed into law a bill toughening penalties for gay people and criminalising those who do not report them.
A government spokesman said President Yoweri Museveni wanted to assert Uganda’s “independence in the face of Western pressure”.
US President Barack Obama has cautioned the bill would be a backward step.
Mr Museveni had previously agreed to put the bill on hold pending US scientific advice.
Homosexual acts are already illegal in Uganda.
In December, a gay rights campaigner spoke of her fears about the legislation
The new law punishes first-time offenders with 14 years in jail, and allows life imprisonment as the penalty for acts of “aggravated homosexuality”.
It also makes it a crime not to report gay people – in effect making it impossible to live as openly gay.
It criminalises the “promotion” and even the mere “recognition” of homosexual relations “through or with the support of any government entity in Uganda or any other non-governmental organisation inside or outside the country”.
Lesbians are covered by the bill for the first time.
Gay activists say they will challenge the new laws in court.
The bill originally proposed the death penalty for some homosexual acts, but that was later removed amid international criticism.
Government officials clapped after Mr Museveni signed the bill at a press conference at State House.
The BBC’s Catherine Byaruhanga in Uganda says it is rare for the president to assent to bills so publicly.
But the anti-gay bill has become so controversial that the media were invited to witness its signing, she says.
I think this will go in Uganda’s history as one of the worst events following Kony [the Lord’s Resistance Army rebel leader] and Idi Amin’s regime. This is going to open doors [for] people to start reporting their friends or people they hate to the police. My brothers or my family if they don’t report me they are also going to be charged.
It is going to be enforced because first of all, you have this majority of people that really don’t like gay people and it is being fired up by members of parliament, [who] want to please their people.
Five years ago things were calm – then the visiting of the US evangelicals [began]. Before then, people never even talked about it. Last month when I went back to Uganda, things had changed a little bit, you had the newspapers having people’s opinions, you had gay people going on radio talk shows … I mean to change people’s attitudes, people have to talk.
Most of these people have this cultural belief in longevity and in extended families; they want a child, a grandchild. [With] homosexuality they start envisioning this world of no people – their legacy is gone – that’s where the whole negativity comes in.
Earlier government spokesman spokesman Ofwono Opondo told Reuters news agency Mr Museveni wanted “to demonstrate Uganda’s independence in the face of Western pressure and provocation”.
The sponsor of the bill, MP David Bahati, insisted homosexuality was a “behaviour that can be learned and can be unlearned”.
“Homosexuality is just bad behaviour, that should not be allowed in our society,” he told the BBC’s Newsday programme.
But a gay rights activist in Uganda told the programme that he was “very scared” about the new bill.
“I didn’t even go to work today [Monday]. I’m locked up in the house.
“And I don’t know what’s going to happen now. I’m talking to all my activists on the phone. And it’s the same, they are all locked up in their houses. They can’t move out. They are watching their back to see what happens.”
Our correspondent says although Mr Museveni had been apprehensive about signing the bill, he could not convince his party, religious groups and many of his citizens that it was not needed.
The signing of the bill is an apparent U-turn from a recent pledge to hold off, pending advice from the US.
In a statement, Mr Museveni had said: “I… encourage the US government to help us by working with our scientists to study whether, indeed, there are people who are born homosexual.
“When that is proved, we can review this legislation.”
President Obama described it as “more than an affront, and a danger to, Uganda’s gay community. It will be a step backwards for all Ugandans.”
He warned it could “complicate” Washington’s relations with Uganda, which receives a reported $400m (£240m) in annual aid from the US.
In South Africa, former archbishop Desmond Tutu said he was disheartened by President Museveni’s apparent change of stance.
What are your views on President Museveni’s anti-gay bill?