Gay rights campaigners in Uganda and around the world are celebrating a decision by the country's constitutional court to strike down a widely condemned anti-gay law on a legal technicality.

Activists in the courtroom cheered after a panel of five judges ruled on Friday that the speaker of parliament acted illegally when she allowed a vote on the measure despite at least three objections that not enough MPs were in attendance.

"The speaker was obliged to ensure that there was quorum," the court said in its ruling. "We come to the conclusion that she acted illegally."

While celebrating the ruling, activists warned that homosexuality remained a criminal offence in the east African country under colonial-era laws.

The fiercely controversial statute represented a dramatic toughening of the penalties. It banned the "promotion of homosexuality" and enabled life sentences to be imposed for various same-sex acts, including touching in public or living in a same-sex marriage. Activists also warned the state could appeal against the ruling in the supreme court and legislators might try to reintroduce new anti-gay measures.

President Barack Obama described the legislation as "a step backward for all Ugandans", and several donors suspended aid. But Uganda's president, Yoweri Museveni, signed it into law in February, watched by cheering crowds. Asked about homosexuality on CNN, Museveni said: "They're disgusting. What sort of people are they? I never knew what they were doing. I've been told recently that what they do is terrible. Disgusting."

The challenge to the law was brought by 10 petitioners, including academics, journalists, both ruling party and opposition MPs, human rights activists and rights groups. They claimed that it violated the constitutional right to privacy and dignity, as well as the right to be free from discrimination and cruel, inhuman and degrading treatment.

Friday's ruling was made in a courtroom packed with opponents and supporters of the measure. Among those present was Frank Mugisha, director of Sexual Minorities Uganda, who said: "We welcome this ruling and Uganda's lesbian, gay, bisexual and transgender community can celebrate a small victory against oppression.

"However, we are disappointed that the case was not heard on its true merits. The truth is that not only is the anti-homosexuality act persecutory, it is also unconstitutional and illegitimate. This law has no place in our society, which values dignity, privacy and equality for all our citizens. Until the act has been dismissed on the substance of our arguments, we cannot rest easy."

Ugandan lawyer Ladislaus Rwakafuuzi, a lawyer representing the activists, said the ruling "upholds the rule of law and constitutionalism in Uganda".

Homophobia is widespread in the socially conservative country, where American evangelical Christian groups have been accused of fuelling prejudice. The legislation was seen as a political ploy by Museveni to shore up support before elections in 2016, which will be his 30th year in power.

The court's intervention allows him to blame others for its defeat while also placating western donors, who were reluctant to punish a military ally.

Outspoken anti-gay preacher Martin Ssempa had suggested that the petition was being pushed to mend Uganda's international reputation before Museveni travels to Washington next week to meet Obama at a landmark US-Africa summit. "There are efforts … to drum up a legal precedent to try to show [Washington] that, 'Hey, we are not that bad on homosexuality,'" Ssempa told Agence France-Presse this week.

The US last month froze some aid programmes, as well as cancelling military air exercises and barring entry to the US for specific Ugandan officials involved in "human rights abuses", including against the gay community.

Rights groups claimed that the law had led to a sharp increase in arrests and assaults on members of the gay and lesbian community. Its annulment was welcomed by the Human Dignity Trust, an organisation of international human rights lawyers challenging anti-gay laws across the world.

Jonathan Cooper, its chief executive, said: "It's a fantastic victory for the rule of law. That Uganda's gay and lesbian community has won a reprieve today from the oppression of the loathsome anti-homosexuality act, we can only celebrate.

"The brilliance and determination of the activists who have pursued this challenge serve as an inspiration to us all. It is also heartening to know that the rule of law has prevailed and politicians are shown not to be above the procedures that govern them.

"However, this is but a temporary fix; the fight is far from over. The international community must seize this opportunity to support Ugandan's gay and lesbian citizens in their battle for the basic freedom from persecution. Now the act has gone, we must do all we can to stop it coming back. Uganda's constitution – which protects citizens' rights to privacy and dignity – must be for all Ugandans."

Dr Paul Semugoma, a Ugandan gay rights activist based in South Africa, said: "I am over the moon. Very happy. But we have had legal victories before. It was struck down on a technicality. It may return.

"In Uganda, homophobia is such an inherent part of culture now that opportunistic politicians are likely to bring it back. They would pass it."

Sarah Jackson, deputy regional director of Amnesty International, said: "Even though Uganda's abominable anti-homosexuality act was scrapped on the basis of a technicality, it is a significant victory for Ugandan activists who have campaigned against this law.

"Since it was first being floated in 2009, these activists have often put their safety on the line to ensure that Ugandan law upholds human rights principles.

"We now hope that this step forward translates into real improvements in the lives of lesbian, gay, bisexual, transgender and intersex people in Uganda, who have been trapped in a vicious circle of discrimination, threats, abuse and injustice for too long."

Kosiya Kasibayo, a state attorney, said that a decision had not been made on whether to appeal against the ruling in the supreme court.