Uganda's Supreme Court has overturned a lower court ruling, which had cast doubt on the entire political system.
Museveni said the original ruling meant that all laws were invalid
The government had appealed against the decision which nullified a 2000 referendum, in which a return to multiparty politics was rejected.
President Yoweri Museveni made an angry television broadcast criticising the judges and his supporters protested in the capital, Kampala.
Donors are urging Uganda to return to a multiparty system.
Under Uganda's Movement system, parties are allowed to exist, but they are not allowed to contest elections.
The Supreme Court ruled that the results of the 2000 referendum were valid but agreed that the act which set up the vote had been unconstitutional.
Mr Museveni had said that the original judgement meant that all government acts since 2000 were null and void.
He said it was "totally unacceptable".
Under pressure from donors, the government has promised to hold multiparty elections in 2006.
Mr Museveni is obliged to step down but his critics say he is preparing the ground to be allowed to run again.