Updated

Kenya faced a photo finish in its race for president on Friday as the last ballots were counted. The leading candidate, Uhuru Kenyatta, saw his percentage yo-yo around the crucial 50 percent mark, as officials told The Associated Press it appeared likely Kenyatta could win a majority.

The latest vote tally showed Kenyatta, the deputy prime minister, with 49.87 percent of the vote. A little more than 80 percent of voting locations had been tabulated. Earlier, Kenyatta briefly broke above 50 percent before the election commission gave another of its frequent updates.

Electoral expert Tom Wolf, a research analyst with the polling firm Ipsos Synovate, told The Associated Press that the outstanding votes coming in from Kenya's Rift Valley are a "very abundant vote basket" for Kenyatta. His running mate, William Ruto, is from the Rift.

"On a scale of zero to 10, it seems to be about a seven or eight that he'll probably just get over" the 50 percent mark, said Wolf. "I would be a little bit more surprised if he didn't get over 50 than if he did, but neither one on the face of it would be a complete surprise."

The 50 percent mark is important for Kenyatta to avoid a runoff with the other top candidate, Prime Minister Raila Odinga.

A Western election observer said the international community was forming a consensus around the belief that Kenyatta was likely to win outright. The observer spoke on condition he wasn't identified talking about internal diplomatic discussions.

There was also a belief that Odinga was not likely to protest the vote in a manner that would increase the chances of violence, the observer said, but rather honor his pledge to respect the result and petition the courts with any grievances.

The election commission announced late Friday afternoon it intended to finish the counting process by the end of the day, but as dark descended on Nairobi, some observers wondered if the election commission would really announce the results at night, when security forces would face a more difficult challenge containing any outbreaks of violence.

Kenya's capital, Nairobi, has been sleepy since Monday's vote for president, the country's first election since its 2007 vote sparked tribe-on-tribe violence that killed more than 1,000 people. But groups of security forces in riot gear took to the streets Friday in regions of the city that could turn tumultuous after results are announced.

The prime minister's supporters took to the streets after Odinga in 2007 said he had been cheated. In Kibera, Nairobi's largest slum and a bastion of Odinga support, many believe this year's results have been rigged as well.

"If you look at the way the tallying is being done there is rigging," said Isiah Omondi, 27. "If Uhuru wins and wins fairly, we don't have a problem with him. He can be our president. But not like this."

A Kenyatta win could have far-reaching consequences with Western relations. The son of Kenya's founding father, Kenyatta faces charges at the International Criminal Court for his role in directing some of the 2007 postelection violence.

The U.S. has warned of "consequences" if Kenyatta is to win, as have several European countries. Britain, which ruled Kenya up until the early 1960s, has said they would only have essential contact with a President Kenyatta.

The U.S. Embassy in Kenya is larger than any American mission in Africa, underscoring Kenya's strong role in U.S. foreign policy. The U.S. also has military forces stationed here near the border with Somalia. Kenya, the lynchpin of East Africa's economy, plays a vital security role in the fight against Somali militants.

Kenyatta's ICC trial is set to begin in July and could take years, meaning that if he wins he may have to rule Kenya from The Hague for the first half of his presidency. Another option is, as president, to decide not to go. But that decision would trigger an international arrest warrant and spark even more damaging effects for Kenya's standing with the West.

Kenyatta has promised to report to The Hague even if he wins the presidency. The ICC on Friday delayed the trial of Kenyatta's running mate, Ruto, until late May.

A pre-election voter survey from Ipsos showed Odinga getting 44.4 percent and Kenyatta getting 44.8 percent. That left 8 percent for the other six candidates and 2 percent for the undecided. Wolf said Kenyatta clearly won over some of that 10 percent to rise to the 50 percent mark. The third place presidential candidate had been predicted to get 5 percent but instead got only about 3 percent.

In order to win outright, Kenyatta must not only more than 50 percent of the vote but also must garner at least 25 percent of the vote in 24 out of Kenya's 47 provinces. Wolf said he thinks both candidates have achieved that threshold but hasn't seen the numbers. Because of the way the election commission announced results that was difficult to immediately determine.

Whether or not Kenyatta finishes with over half of the votes, most observers expected legal challenges to be launched after a myriad of failures in the systems Kenya's electoral commission set up.

The first problems were evident right as the voting began early Monday. An electronic voter ID system intended to prevent fraud failed across the country for lack of electricity in some cases and overheating computers in others. Vote officials instead used manual voter rolls.

After the polls closed, results were to be sent electronically to Nairobi, where officials would quickly tabulate a preliminary vote count in order to maximize transparency after rigging accusations following the 2007 vote. But that system failed too. Election officials have indicated that computer servers overloaded but have yet to fully explain the problem.

On Tuesday, as the early count system was still being used, election results showed more than 330,000 rejected ballots, an unusually high number. But after the count resumed with the arrival in Nairobi of manual tallies, the number of rejected ballots were greatly reduced, and the election commission on Thursday gave the head-scratching explanation that the computer was mistakenly multiplying the number of rejected ballots by a factor of eight.

Odinga's camp on Thursday said some votes had been doctored and called for a halt to the tallying process. It said the tallying process "lacked integrity." A day earlier, Kenyatta's camp accused the British high commissioner of meddling in the election and asked aloud why there were an unusually high number of British troops in the country.

The election commission has denied any of the results have been altered.

There were fears going into the election that the violence that rocked Kenya five years ago would return. A separatist group on the coast launched attacks on Monday that ended in the deaths of 19 people, but the vote and its aftermath has otherwise been largely peaceful.

However, it's the announcement of results that could stir protests, especially if the supporters of either Odinga or Kenyatta feel robbed. Diplomats say that the public reaction to an election loss by the losing candidate will set the tone for whether violence breaks out.

The political battle between the families of Kenyatta and Odinga goes back to the 1960s and to the two candidates' fathers. Jomo Kenyatta was Kenya's first president after the end of British colonial rule. Jaramogi Oginga Odinga served as the country's first vice president then. The two later had a falling out.

If a runoff is declared, it would be most likely held in late April, depending on how long legal challenges take.