Uganda’s Constitutional Court has annulled tough anti-gay legislation signed into law by President Yoweri Museveni in February.
It ruled that the bill was passed by MPs in December without the requisite quorum and was therefore illegal.
Homosexual acts were already illegal in Uganda, but the new law also banned the promotion of homosexuality and covered lesbians for the first time.
Several donors have cut aid to Uganda since the law was adopted.
The law’s supporters said they would appeal the ruling at the Supreme Court.
“The retrogressive anti-homosexuality act of Uganda has been struck down by the constitutional court — it’s now dead as a door nail,” said Andrew Mwenda, one of 10 petitioners.
The law, signed by Uganda’s veteran President Yoweri Museveni in February, said that homosexuals should be jailed for life, outlawed the promotion of homosexuality and obliged Ugandans to denounce gays to the authorities.
But homosexuality remains illegal and punishable by jail sentences under previous legislation, which is expected to be returned after the court’s decision.
Lawmakers could also seek to reintroduce a bill back into parliament, a potentially lengthy process, with the last such bill taking four years from introduction to the final vote.
But gay rights activists were celebrating on Friday.
“I am no longer criminal, today we have made history for generations to come,” said Kasha Jacqueline, another petitioner and a prominent gay rights activist.
Outspoken anti-gay preacher Pastor Martin Ssempa led prayers before the hearing inside the tightly packed courtroom calling for the judges to uphold the law.
Ssempa had already warned he feared the “judicial abortion of our bill” due to international pressure, and said immediately he would appeal the ruling.
“We are determined to appeal this case at the Supreme Court,” he said.
US Secretary of State John Kerry has likened the law to anti-Semitic legislation in Nazi Germany.
Critics have said Museveni signed the law to win domestic support ahead of a presidential election scheduled for 2016, which will be his 30th year in power.
But Western nations made a raft of aid cuts to Uganda’s government in protest since the law was passed.
Rights groups say the law triggered a sharp increase in arrests and assaults of members of the country’s lesbian, gay, bisexual and transgender (LGBT) community.