A Nigerian tribunal has dismissed both opposition petitions asking that President Umaru Yar'Adua's election last year be annulled.
Mr Yar'Adua leads Africa's largest oil producer and most populous nation
The panel of five judges unanimously rejected them, saying they did not contain enough evidence.
Lawyers for both losing presidential candidates, Muhammadu Buhari and Atiku Abubakar, say they will take their cases to the Supreme Court.
International observers said the April polls fell short of expected standards.
The 2007 election saw the first transfer of power from one elected leader to another in Africa's biggest oil producer and most populous country.
Correspondents say a Nigerian president has never lost an election challenge but the decision was not a foregone conclusion.
The country's courts have been exerting their independence recently - overturning other controversial results from the disputed elections.
The BBC's Andrew Walker in court says the ruling is a considerable blow to the opposition but it will also let the president get on with his job of running the country.
He says the ruling will fly in the face of what many Nigerians experienced during the election but most have already accepted Mr Yar'Adua's election.
Security had been tight in the capital, Abuja, in the run-up to the ruling and no big crowds were allowed to gather outside the courtroom.
"The broader issue of how you get legitimacy as a president in Nigeria rests much more with what you do in government," African analyst Anthony Goldman told the BBC.
The verdict was read out point by point for over three hours by judges in powdered wigs and black gowns.
"Umaru Yar'Adua and Goodluck Jonathan remain validly elected as president and vice-president of Nigeria," the ruling said, AFP news agency reports.
Judge Abdulkadir Abubakar Jega said both sides had failed to prove that violations of the electoral law were substantial enough to invalidate the election result.
The official results show that Mr Yar'Adua gained more than 70% of the vote, compared to 18% for Mr Buhari and 7% for Mr Abubakar.
"From a political stability perspective, this is likely to be positive," African economist Razia Khan told Reuters news agency.
Neither opposition candidates claim they actually won the election - they had called for a re-run.
Mr Yar'Adua has admitted there were flaws in the vote and has promised to reform the electoral system before the next elections.
Mr Buhari, who also contested the previous election in 2003 and is a former military ruler of Nigeria, maintains the vote did not take place in 29 of the 36 states.
His lawyers had unearthed records from Nigeria's election regulator that appeared to show the results had been artificially inflated between the tallying station and being announced.
Mr Abubakar had said the vote should be nullified because the ballot papers were delivered on the day of the election and were missing serial numbers.
Both Mr Buhari (l) and Mr Abubakar (r) want a Supreme Court ruling
The former vice-president fought a long legal battle before the election to be included on the ballot after he fell out with then-President Olusegun Obasanjo in the latter stages of his final term.
The result was the ballot papers had to be re-printed at short notice in South Africa, the court has heard.
They did not reach polling stations in many parts of the country until after the election.
The lack of serial numbers also rendered any result inadmissible, Mr Abubakar's lawyers claimed.
Before the ruling, his spokesman Garba Shehu said politicians could not be "trusted to correct themselves" and the courts had to do it.
The election was widely condemned in the press, but presidential spokesman Mobolanji Adebiyi said the judges would rule on what was in front of them, not on the media reports.
Seven state governors have had their elections overturned by tribunals.
On Saturday a court also annulled the election of Senate President David Mark.
If the presidential election is annulled, he would have taken over during the 90-day period before fresh elections are required to be held.