NAIROBI, Kenya — A Ugandan court struck down a punitive anti-gay law on Friday that has strained Uganda’s relations with the West, but the court ruled on narrow technical grounds, preserving the possibility that the measure could be revived.

In front of an overflowing courtroom in Uganda’s capital, Kampala, a panel of five judges announced that the Anti-Homosexuality Act, which punishes some homosexual behavior with life in prison, was invalid because it had been passed by Parliament without a proper quorum.

“We’re very happy,” said Sylvia Tamale, a Ugandan law professor who has supported gay rights despite persistent threats and harassment. “But it’s unfortunate that the court did not deal with the substantive issues that violate our rights.”

Uganda’s government, which is tightly controlled by President Yoweri Museveni, a former guerrilla fighter who has ruled for 28 years, did not immediately indicate if it was going to appeal the court’s ruling.