Kenya's Deputy Prime Minister Uhuru Kenyatta has been confirmed as the winner of the presidential election.
Mr Kenyatta won 50.07% of the vote on a turnout of 86%, officials said, narrowly avoiding a run-off ballot.
However, his main rival, PM Raila Odinga, alleged voting irregularities and is expected to file a challenge.
Mr Kenyatta is also set to face trial at the International Criminal Court in The Hague over violence that followed Kenya's 2007 elections.
He is accused of fuelling the communal violence that saw more than 1,000 people killed and 600,000 forced from their homes.
The IEBC said the latest elections had been complex and difficult but also credible and transparent.
It said the turnout was the largest ever.
Independent Electoral and Boundaries Commission (IEBC) chairman Issack Hassan said that Kenyans had voted "calmly, patiently, proudly and peacefully in the full glare of whole world".
Announcing the final vote count, he said: "I therefore declare Uhuru Kenyatta the duly elected president of the Republic of Kenya."
Mr Hassan praised the candidates who had already conceded defeat and urged others to follow suit.
However, one of Mr Odinga's aides - speaking before the announcement - said the candidate had "no intention" of conceding defeat.
Salim Lone told the Daily Nation newspaper: "The level of the failures in the system makes it very difficult to believe it was a credible result."
Both candidates have complained of irregularities during the course of the count, since Monday's election.
Mr Kenyatta won 6,173,433 votes out of a total of 12,330,028.
Mr Kenyatta's Jubilee Coalition party said it was "proud and honoured for the trust" bestowed on it, adding that it had taken a message to the people and that "we are grateful to the people of Kenya for accepting this message".
Early on Saturday, small groups of Kenyatta supporters celebrated in Nairobi, hooting car horns and singing.
But the newly confirmed president could face difficult relations with Western countries.
He faces trial at the International Criminal Court (ICC) in July for crimes against humanity.
Mr Kenyatta's running mate, William Ruto, also faces similar charges. Both men deny the accusations.
The ICC has agreed to postpone Mr Ruto's trial by a month until May after his lawyers complained of not having enough time to prepare his defence.
Countries including the US and UK have hinted that Mr Kenyatta's election as president would have consequences for their relations with Kenya - comments which have been dismissed in Nairobi as unwanted foreign interference in domestic matters.
Kenya's new electronic voting system was designed to eliminate the chance of vote-rigging and with it any risk of a repeat of the post-poll violence of 2007.
But the count has been plagued with technical glitches, including a programming error that led to the number of rejected votes being multiplied by a factor of eight.
The prime minister's Cord alliance had earlier complained that votes from 11 constituencies were missing, in effect leaving him more than 250,000 votes short.
Both men passed a second condition needed for victory - at least 25% of the vote in more than half of the 47 counties.