Uhuru Kenyatta, indicted for crimes against humanity, was declared winner of Kenya's presidential election on Saturday with a tiny margin, just enough to avoid a run-off after a race that has divided the nation along tribal lines.
Kenyatta, the son of Kenya's founding president, faces trial after the disputed 2007 presidential vote that unleashed a wave of tribal blood-letting.
The United States and other Western powers, big donors to the east African nation, said before the vote that a Kenyatta win would complicate diplomatic ties with a nation viewed as a vital ally in the regional battle against militant Islam.
After saying Kenyatta secured 50.07 percent of the votes, just achieving the more than 50 percent needed to avoid a second round, the chairman of the Independent Electoral and Boundaries Commission, Issack Hassan, announced:
"I therefore declare Uhuru Kenyatta the duly elected president of the Republic of Kenya," he said. Shortly afterwards he handed a certificate of the results to Kenyatta, who had arrived after the declartion. Kenyatta thanked him.
Many in the election centre cheered, although celebrations started in the early hours of Saturday after provisional results showed Kenyatta's victory. Supporters thronged the streets of Nairobi and his tribal strongholds, lighting fluorescent flares and waving tree branches and chanting "Uhuru, Uhuru".
The mood was tense but calm in the heartlands of Kenyatta's rival, Prime Minister Raila Odinga, who also lost in the disputed 2007 vote and trailed this time with 43.3 percent.
"No Raila, no peace," Odinga supporters chanted as security forces stood by in Kisumu, a city where violence flared in 2007.
Speaking before the formal declaration, a close adviser to Odinga said his candidate would challenge the result if Kenyatta was declared winner.
Odinga's camp had said during tallying that the ballot count was deeply flawed and had called for it to be halted. But they promised to pursue any disputes in the courts not the streets.
The election commission, plagued by technical problems that slowed the count, took five days to announce the result.
International observers broadly said the vote and count had been transparent so far and the electoral commission, which replaced an old, discredited body, promised a credible vote.
Kenyatta, the deputy prime minister, achieved the 50 percent mark by a tiny margin of about 8,400 votes out of the more than 12.3 million that were cast.
Both sides relied heavily on their ethnic groups in a nation where tribal loyalties mostly trump ideology at the ballot box. Kenyatta is a Kikuyu, the biggest of Kenya's many tribes, Odinga is a Luo. Both had running mates from other tribes.
John Githongo, a former senior government official-turned-whistleblower, urged the rival coalitions, Odinga's CORD and Kenyatta's Jubilee, to ensure calm. "Jubilee and CORD, what you and your supporters say now determines continued peace and stability in Kenya. We are watching you!" he said on Twitter.
How Western capitals deal with Kenya under Kenyatta and the extent they would be ready to work with his government will depend heavily on whether Kenyatta and his running mate William Ruto, who is also indicted, cooperate with the tribunal.
"It won't be a headache as long as he cooperates with the ICC," said one Western diplomat. "We respect the decision of the majority of the Kenyan voters."
Both Kenyatta and Ruto deny the charges and have said they will work to clear their names, though Kenyatta had to fend off jibes during the campaign by Odinga that he would have to run government by Skype from The Hague.
"Until now, Kenyatta has been cooperating with the court and we do hope this will continue," said Fadi El-Abdallah, spokesman for the Hague-based court. "This is part of Kenya respecting its legal obligations under international law."
Kenyans hope the vote, which has so far passed off with only pockets of unrest on voting day, would restore their nation's reputation as one of Africa's most stable democracies after killings last time left more than 1,200 dead.
Many Kenyans have said they are determined to avoid a repeat of the post-2007 chaos that brought the economy to a halt.
Church leaders in Kisumu, in the west of Kenya that was devastated five years ago, sought to defuse tension this time.
"Our vote was stolen and we're angry," said Denis Onyango, a 28-year-old mechanic, as hundreds of Odinga supporters gathered with members of the security forces nearby. "Why did they bring such huge security here if the vote was to be free and fair."
Some said it was time to move on. "I urge our candidate to forget the presidency and let the will of God prevail," said cloth vendor Diana Ndonga.
"We are heading for a bleak future where the economy goes down and international relation sour because of the ICC case," said Athumani Yeya, 45, a teacher in the city.
Others were hopeful that Kenyatta could bring change.
"We are celebrating. Even with the ICC case in Holland, the people of Kenya still have faith in him," said Thomas Gitau, 25, a bare-foot car washer on a main Mombasa street. "We hope he can fix infrastructure and security so we have more jobs."
Odinga's camp had said even before the result that they were considering a court challenge. In 2007, he said the courts could not be trusted to handle the case. Kenyatta's camp had also complained about counting delays and other aspects of the vote.
But many Kenyans said this race was more transparent. Turnout reached 86 percent of the 14.3 million eligible voters.
Addigional reporting by James Macharia, Beatrice Gachenge and George Obulutsa in Nairobi, Hezron Ochiel in Kisumu, Drazen Jorgic in Mombasa and Thomas Escritt in Amsterdam; Writing by Richard Lough and Edmund Blair; Editing by Alison Williams