Kenya is on tenterhooks as it awaits results from Tuesday's election, which passed off relatively smoothly despite some issues with malfunctioning voter identification equipment, delays at polling stations and scattered incidents of violence.
But with the race currently too close to call between presidential frontrunners William Ruto and Raila Odinga and what could be a low turnout by Kenyan standards, the risk of yet another contested election is high.
No Kenyan presidential poll outcome has gone unchallenged since 2002, and memories are still raw of the bloodshed that erupted after disputes over two of the last three elections.
Kenya's Independent Electoral and Boundaries Commission must announce the results by August 16, but the longer the wait the greater the risk of tensions, analysts say.
"We call for patience among Kenyans as we undertake this rigorous exercise and also endeavour to complete this exercise as soon as possible," IEBC chairman Wafula Chebukati said late Tuesday.
The process is complicated, with results from more than 46,000 polling stations across the country to be counted, cross-checked and tallied.
In addition to voting for president, Kenyans were also choosing new MPs, senators, women representatives as well as county governors and officials.
Final presidential results will be announced at the IEBC's national tallying centre, based at a tourist village known as the Bomas of Kenya.
It has been transformed into a virtual fortress, with no one admitted without accreditation and armed guards and sniffer dogs ensuring security.
The winner of the presidential race needs to secure 50 percent plus one vote and at least a quarter of the votes in 24 of the 47 counties.
If neither Odinga nor Ruto gets over the threshold, a run-off must be held within 30 days of the original election -- something that would be a first in Kenyan history.
Any challenge to the results must be made within seven days to the Supreme Court, the country's highest judicial body.
The court has a 14-day deadline to issue a ruling, and if it orders an annulment, a new vote must be held within 60 days.
If no candidate files a petition, the winner takes office two weeks after final results are announced.
One scenario, albeit seen as the most unlikely, suggested that if there were multiple run-offs and petitions, there may not be a new president until late April or early May next year.
Ben Hunter, Africa analyst at risk intelligence group Verisk Maplecroft, said the court system in Kenya was one of the region's most "robust".
"If the result is contested, a candidate filing a petition with the Supreme Court would be a positive step because the alternative is calling supporters out in protest.
"The court enjoys strong credibility and a legal process would act as a release valve for political tensions."
The African Union, the European Union and the Commonwealth are among those that have sent observers to monitor the polls, along with several civil society groups.
Odinga, 77, ran unsuccessfully for the presidency in 1997, 2007, 2013 and 2017, claiming to have been robbed of victory in the last three elections.
In a first for Africa, the Supreme Court annulled the August 2017 result after Odinga rejected the results, saying hackers broke into the electoral body's database.
The court declared President Uhuru Kenyatta's win null and void because of widespread "irregularities and illegalities" in the counting process and mismanagement by the IEBC.
Dozens of people were killed in what was blamed on police brutality in the chaos and acrimony that followed.
Kenyatta went on to win the rematch after a boycott by Odinga.
In the deadliest election violence, more than 1,100 people were killed and many thousands more displaced in bloodletting between rival tribes after the 2007 vote.
The clashes erupted after Odinga claimed incumbent Mwai Kibaki's victory had been rigged.
Ruto and Kenyatta were charged by the International Criminal Court over the unrest but the cases were later dropped.