Uganda's Constitutional Court on Wednesday rejected a bid to scrap a controversial anti-gay law that is considered one of the toughest in the world.
The legislation was adopted in May last year, triggering outrage among the LGBTQ community, rights campaigners, the United Nations and Western powers.
It imposes penalties of up to life in prison for consensual same-sex relations and contains provisions that make "aggravated homosexuality" an offence punishable by death.
"We decline to nullify the Anti-Homosexuality Act 2023 in its entirety, neither will we grant a permanent injunction against its enforcement," said Richard Buteera, Uganda's deputy chief justice and head of the court.
The decision was greeted with dismay by opponents of the law, although the five-judge bench did strike out several provisions it said were inconsistent with international rights conventions.
These included provisions making it an offence to fail to report homosexual acts, to lease premises for such acts, or if someone engaging in homosexual sex led the other to contract a terminal illness.
But "the upshot of our judgement is that this petition substantially fails", Buteera said.
In Geneva, UN Human Rights Commissioner Volker Turk again urged Uganda to repeal the law "in its entirety, together with other discriminatory legislation".
"Criminalisation of and application of the death penalty to consensual same-sex relations are contrary to Uganda's international human rights treaty obligations," Turk said.
The United States, which has restricted visas for Ugandan officials and removed Kampala from a key trade pact after the law, warned it will keep taking "appropriate measures".
The law is "part of the broader degradation of human rights protections that puts all in Uganda at risk and damages the country's reputation", State Department spokesman Matthew Miller said.
Amnesty International said it was "shocking" that the court missed the opportunity to revoke the "callous" law.
The ruling comes amid an anti-gay crackdown by governments in East Africa, which has a history of repression against gay people, often encouraged by conservative Muslims and Christians.
Nicholas Opiyo, the lawyer representing the petitioners, said they would study the ruling before deciding on the next steps.
"You come to court expecting it to rise above public bigotry and sentiments. To that extent, it is a letdown," he posted on X.
The petition was brought by two law professors, legislators from the ruling party and human rights activists.
They had charged that the legislation violated fundamental rights guaranteed by Uganda's constitution, including freedom from discrimination and the right to privacy.
The petitioners also said it contravened Uganda's commitments under international human rights law, including the United Nations convention against torture.
MP Fox Odoi-Oywelowo, a member of President Yoweri Museveni's National Resistance Movement who spoke out against the law, told AFP it "should have been struck down long ago".
Oryem Nyeko, researcher at Human Rights Watch, said the decision was "disappointing and a missed opportunity in regard to safeguarding fundamental human rights".
But Uganda's parliament speaker Anita Among hailed the ruling.
"The ruling proves that all arms of government, the parliament, the executive and the judiciary have one common goal of protecting Uganda against negative foreign influence," she told AFP.
Museveni's government has struck a defiant tone, with officials accusing the West of trying to pressure Africa into accepting homosexuality.
And the measures have enjoyed broad support in the conservative, predominantly Christian country.
Last August, a 20-year-old man became the first Ugandan to be charged with "aggravated homosexuality" under the contested law.
The World Bank announced in August it was suspending new loans to Uganda over the law.
In December, Ugandan state minister for foreign affairs Henry Okello Oryem accused the West of seeking "to coerce us into accepting same-sex relationships using aid and loans".
Last month, a Ugandan court dismissed an appeal by a gay rights group seeking government registration, ruling that it aimed to promote "unlawful" activities.