Uganda's Supreme Court has narrowly rejected a challenge to presidential election results brought by opposition leader Kizza Besigye.
President Museveni was cleared of breaking electoral laws
The court ruled by a four-three majority that there was no evidence that the results had been substantially affected by irregularities.
The judges found there had been problems but not enough to challenge President Yoweri Museveni's victory.
On Tuesday, Dr Besigye denied treason charges at the start of his trial.
He says the charges were political and designed to distract him from February's elections. Last month, he was cleared of a rape charge.
The Supreme Court dismissed Dr Besigye's call for a recount of the vote, or even holding the elections again.
The judges, however, agreed that there had been irregularities in the poll:
- The disenfranchisement of voters, with names struck off the voters' role
- Counting and tallying irregularities
- A free and fair election had been compromised by bribing, intimidation and violence
- Problems of multiple voting and ballot box stuffing in some areas.
Despite these flaws, a majority ruled that Dr Besigye's team had not proved that these failures had affected the overall result.
"It is hereby ordered that the petition be dismissed," Chief Justice Benjamin Odoki said.
Mr Museveni received 59% of the vote, against 37% for Dr Besigye.
Five judges to two ruled that Mr Museveni did not commit illegal practices either personally or through his agents.
Dr Besigye's lawyers had accused the president of breaking electoral laws by accusing the opposition leader of having links to "terrorist groups".
BESIGYE IN COURT
Treason: Pleaded not guilty
Terrorism: Army appealing against dismissal
Weapons offences: Army appealing against dismissal
Election challenge: Dismissed
Besigye may sue for wrongful arrest
Mr Museveni is now be sworn in next month.
Dr Besigye rejected the ruling, saying he would continue to regard Mr Museveni's presidency as illegitimate.
He also filed a suit against the results of the 2001 election - again a narrow majority ruled that there had been problems but not enough to affect the result.
Mr Museveni has ruled Uganda for 19 years and had been seen as part of a "new generation" of African leaders.
But he was criticised for changing the constitution to enable him to stand in this year's polls.
Dr Besigye used to be Mr Museveni's personal doctor. The two men were allies in the guerrilla war which brought Mr Museveni to power but the pair fell out and were election rivals in 2001 as well as this year.
After losing the 2001 poll, Dr Besigye fled Uganda saying he feared for his life. He returned last year.