Zambia's Supreme Court has thrown out a challenge to President Levy Mwanawasa's election victory but said the December 2001 ballot had flaws.
The president had said he would resign if the judges ruled the vote was flawed
Judges said the three opposition candidates who lodged the appeal had only managed to prove six of the 36 allegations against the vote.
Chief Justice Ernest Sakala said: "The results were potentially perfect."
There were clashes between rival party supporters outside the court ahead of the ruling on the legal action.
Police fired tear gas to break up a fight between ruling party supporters and an opposition supporter.
Chief Justice Sakala said: "We therefore declare that Levy Mwanawasa was duly elected as president of Zambia.
"We are satisfied that despite the flaws in the electoral process, the results were potentially perfect."
Two of the claimants, Anderson Mazoka and Christon Tembo, wanted the elections scrapped, alleging vote-rigging and vote-buying, while Godfrey Miyanda was calling for a recount.
President Mwanawasa had said he would leave office if the poll was found to be invalid.
He narrowly won presidential elections more than three years ago, which opposition parties claim were subject to fraud and ballot-rigging.
Confident of a positive outcome, Mr Mwanawasa's ruling Movement for Multiparty Democracy supporters had been singing and drumming outside court throughout the day.