Uganda's constitutional court struck down on Friday an anti-homosexuality law that punishes gay sex with long jail sentences, citing procedural irregularities in the way the legislation was enacted.
Under the Anti-Homosexuality Act, those convicted of "aggravated homosexuality" faced punishments of up to life in prison and seven years for "aiding and abetting homosexuality".
The law, which came into effect in February, drew widespread protest from western countries, some of which responded by cutting aid to Uganda.
"I can confirm the anti-homosexuality law has been struck down. The judge said there were irregularities in the process of its enactment and also there was no quorum in parliament," said Nicholas Opio, a lawyer for petitioners to the court.
The petition had alleged that the law violated fundamental rights.
The constitutional court ruling can be challenged through an appeals process, lawyers said.
Fear of violence, imprisonment and loss of jobs means few gays in Africa are open about their sexuality.