Uganda’s Constitutional Court on Wednesday largely upheld a sweeping anti-gay law that President Yoweri Museveni signed last year, undermining the efforts of activists and rights groups to abolish legislation that drew worldwide condemnation and strained the East African nation’s relationship with the West.

The legislation, which was signed into law by Mr. Museveni in May, calls for life imprisonment for anyone who engages in gay sex. Anyone who tries to have same-sex relations could face up to a decade in prison.

Uganda has faced international consequences for passing the law, with the World Bank suspending all new funding and the United States imposing sanctions and visa restrictions on top Ugandan officials. But the law was popular in Uganda, a landlocked nation of over 48 million people, where religious and political leaders frequently inveigh against homosexuality.

The fallout for Uganda will be watched closely in other African countries where anti-gay sentiment is on the rise and anti-gay legislation is under consideration, including in Kenya, Namibia, Tanzania and South Sudan. In February, Ghana’s Parliament passed an anti-gay law, but the country’s president said that he would not sign it until the Supreme Court ruled on its constitutionality.

In Uganda, the five-judge bench said the law violated several key rights granted in the country’s Constitution, including the right to health and privacy. But in their 200-page judgment, they largely rejected the request to quash the law.

“We decline to nullify the Anti-Homosexuality Act 2023 in its entirety, neither will we grant a permanent injunction against its enforcement,” Richard Buteera, one of the judges, said in a reading of the judgment’s summary to a packed courtroom.