Kenya's President Uhuru Kenyatta has secured a second term in office, setting off wild street celebrations by his supporters and protests in opposition strongholds in the capital and the west of the country.
Speaking after the result of Tuesday's election was announced, Mr Kenyatta offered an olive branch to the opposition, urging national unity and peace with rivals who have rejected the result and raised the prospect of street protests.
Many Kenyans fear a repeat of the violence that followed the 2007 disputed election, when about 1,200 people were killed and hundreds of thousands displaced as protests over the result led to ethnic killings.
Mr Kenyatta got 54.3 per cent of the vote, ahead of rival Raila Odinga who secured 44.7 per cent, according to election commission figures.
Nearly 80 per cent of the 19 million registered voters cast their ballots.
"To my worthy competitor Raila Odinga, I reach out to you, I reach out to your supporters, let us work together," Mr Kenyatta, 55, said, shortly after being declared winner.
"Let us be peaceful, let us share together," he said.
"Reach out to your neighbour, shake their hand. Say this election is over, let us move on."
In Nairobi and other towns in Kenya his supporters took to the streets to celebrate, honking car horns and blowing whistles.
However, there were also protests.
Police fired tear gas and gunshots were heard in the Nairobi slums of Mathare and Kawangware, where young men took to the streets as police helicopters buzzed overhead.
In Kisumu, an Odinga stronghold in the west, youths banged drums and tyres burned in the streets in the Kondele district.
As election officials prepared the final results, the National Super Alliance (NASA) opposition coalition, led by 72-year-old Mr Odinga, said it rejected the process after its complaints had not been addressed.
"We raised some very serious concerns. They have not responded to them. As NASA we shall not be party to the process they are about to make," senior opposition official Musalia Mudavadi told reporters.
James Orengo, one of Mr Odinga's top lieutenants, said the process had been a "charade".
He stopped short of calling for protests but praised the Kenyan people's history of standing up to stolen elections and said there were "constitutional alternatives" to challenging any result.
Mr Odinga has lost the last two elections amid complaints of fraud.