KAMPALA, Uganda — A Ugandan court has invalidated an anti-gay bill signed into law earlier this year, saying it was illegally passed and is therefore unconstitutional.

The panel of five judges on the East African country’s Constitutional Court said the speaker of parliament acted illegally when she went ahead to allow a vote on the measure despite at least three objections over lack of quorum.

The ruling was made before a courtroom packed with Ugandans opposing or supporting the measure. Activists erupted in loud cheers after the court ruled the law is now “null and void.”

The anti-gay measure provided for jail terms of up to life for those convicted of engaging in gay sex. It also allowed lengthy jails terms for those convicted of the offenses of “attempted homosexuality” as well as “promotion of homosexuality.”

Although the legislation had wide support in Uganda, it had been condemned in the West and rights groups have described it as draconian. The U.S., which wanted the law repealed, had withheld or redirected funding to some Ugandan institutions accused of involvement in rights abuses.

The law was passed by lawmakers in December and enacted in February by Ugandan President Yoweri Museveni, who said he wanted to deter Western groups from promoting homosexuality among African children.