Kenya's election commission announced early Saturday that Deputy Prime Minister Uhuru Kenyatta had prevailed in the country's presidential elections by the slimmest of margins, winning 50.03% of the vote according to provisional figures.

Diplomats were worried they might have to weaken ties with the east African nation if Kenyatta is elected because he faces charges of crimes against humanity at the International Criminal court at The Hague. The result will almost certainly be challenged in the courts by his opponent, the prime minister Raila Odinga.

The ballot went off relatively smoothly on Monday, despite widespread fears of violence. Five years ago, more than 1,200 people were killed and hundreds of thousands displaced over disputed polls, and Kenyatta is accused of organising that violence. But, apart from a few coastal skirmishes, this time the elections were peaceful, winning praise from international observers.

However, the count was marred by delays and technological breakdowns. The problems began almost immediately when thousands of electronic voter identification devices failed, forcing poll workers to use the slower method of printed lists. Once voting finished, bigger problems started, beginning with a glitch in an electronic transmission system designed to securely send results to the national tallying centre in Nairobi.

The Independent Electoral and Boundaries Commission identified the problem as low disk space, which caused a slowdown in transmission, and declared the issue solved.

But by Wednesday afternoon, only 40% of results were in, so IEBC chairperson, Ahmed Issack Hassan, decided to scrap the whole apparatus and call the 291 constituency officers to Nairobi for a manual tally.

That decision brought even more headaches. "The electronic transmission was to be verified by the manual form," said Maina Kiai, founder of the Kenya Human Rights Commission.

"When you kill that off, the only record is the manual, and that was the whole problem the last election." With no backup, Hassan has simply asked Kenyans to trust him. Hassan tried to expedite things by barring observers and political party agents from the tallying centre floor. But that led Odinga's running mate, Kalonzo Musyoka, to demand an immediate halt to the "doctored" process.

Another challenge came from the African Centre for Open Governance (AfriCog), which has filed a suit against the IEBC to stop tallying until all concerns were addressed.

That case was thrown out, but further legal actions are expected.

From the outset, Kenyatta had kept ahead, hovering around 50% of cast votes compared with Odinga's rough 43%. If Kenyatta had not broken through the 50% barrier he would have faced a runoff next month. Kenyans hoped this vote would restore their nation's reputation as one of Africa's most stable democracies after the tribal slaughter that followed the disputed 2007 vote that Odinga said Mwai Kibaki stole from him.

The test will be whether any challenges to the outcome are worked out in the courts of the newly reformed judiciary, and do not spill over into the streets, as they did in 2007.