Kenya's Supreme Court has upheld Uhuru Kenyatta's presidential election victory, rejecting several petitions challenging the vote.
Chief Justice Willy Mutunga announced the decision, which was unanimous, saying the poll was free and fair.
The appeal was lodged by PM Raila Odinga, Mr Kenyatta's main rival in the presidential poll this month.
Official results said Mr Kenyatta beat Mr Odinga by 50.07% to 43.28%, avoiding a run-off by just 8,100 votes.
There was tight security at the Supreme Court as the judgement was read out. Violence after a disputed election in 2007 left more than 1,200 people dead.
The presidential, legislative and municipal elections held on 4 March were the first since the 2007 poll.
Mr Kenyatta and his running mate, William Ruto, will be sworn in as president and vice-president early next month.
But they are facing trial on charges of crimes against humanity at the International Criminal Court (ICC) for allegedly fuelling unrest after that election. They deny the charges.
Plea for calm
Chief Justice Mutunga said the court's decisions had been unanimous on all the issues they were asked to rule on.
He said that Mr Kenyatta and Mr Ruto had been "validly elected" in a poll carried out in a "free, fair, transparent and credible" manner.
"It is the decision of the court that the said elections were indeed conducted in compliance with the constitution and the law," he said.
Before he delivered the ruling, all roads leading to the building were closed.
Police chief David Kimaiyo warned on Friday that unrest would not be tolerated.
He said: "We have reports indicating that some parties have organised their supporters to converge outside the Supreme Court during delivery of the ruling, and we will not allow any such gatherings.
"There will be tight security in all parts of the country, we will not tolerate any form of violence."
Outgoing President Mwai Kibaki has urged people to stay calm and accept the result, but much will depend on Kenyans' faith in their newly reformed judiciary, says the BBC's Gabriel Gatehouse in Nairobi.
Lawyers for Mr Odinga said their petition to the Supreme Court included allegations of vote manipulation, as well as problems with the registration of voters and an electronic vote counting mechanism.
On Friday, the Supreme Court reviewed recounts from 22 polling stations. Both sides claimed that the recounts vindicated their position.
Mr Kenyatta has called the election, which was largely conducted peacefully, a "triumph of democracy".
The Independent Electoral and Boundaries Commission (IEBC) has insisted that the vote was credible, despite technical failures with an electronic voter ID system and the vote counting mechanism.
International observers said the poll was largely free, fair and credible, and that the electoral commission had conducted its business in an open and transparent manner.