KAMPALA, Uganda—Uganda's constitutional court nullified a recently enacted antigay law that had been derided as draconian by human-rights activists and Western governments.

A panel of five judges ruled that the parliament had passed the bill without the necessary number of lawmakers present, rendering it null and void.

"The speaker violated...