NAIROBI, Kenya — Kenya’s vice president, William Ruto, won the country’s presidential election, the head of the electoral commission said Monday, days after a cliffhanger vote in a country that is pivotal to the economy and security of East Africa.
Mr. Ruto gained 50.5 percent of the vote, narrowly defeating Raila Odinga, a former prime minister, said the chairman of the Independent Electoral and Boundaries Commission, Wafula W. Chebukati. That percentage is enough to warn a runoff vote.
But minutes before the result was announced, four of the seven commission members said they could not verify the outcome. The statement raised questions about the legitimacy of the result and is likely to feature in any challenge in Kenya’s Supreme Court by supporters of Mr. Odinga.
A legal challenge could, in the short term, prolong a period of uncertainty in a nation whose democracy is closely watched by the continent and the world.
Kenyan law allows for an election result to be challenged within one week — a prospect that many observers viewed as a near certainty.
Soon after the results were announced, Mr. Ruto accepted victory, thanked his supporters and vowed to work for the good of the country.
“There is no room for revenge, there is no room for looking back, we are looking into the future,” he said. “I am acutely aware that our country is at a stage where we need all hands on deck to move it forward. We do not have the luxury to look back.”
Celebrations broke out in the streets of Eldoret town, a stronghold for Mr. Ruto’s in the Rift Valley, with a deafening cacophony of cars and motorcycle honks, whistling and screaming taking over the streets in the downtown area.
Speaking later, Mr. Ruto dismissed the declaration by the four electoral commissioners as a “side show.” Under the law, he said, the election results could be declared only by Mr. Chebukati.
“Legally, constitutionally, the four commissioners pose no threat at all to the legality of the declaration,” he said.
His camp has noted that the four — Juliana Cherera, Francis Wanderi, Justus Abonyo Nyang’aya and Irene Cherop Masit — were appointed by President Uhuru Kenyattawho had campaigned for Mr. Odinga.
Mr. Ruto, 55, a wealthy businessman, has cast himself as the champion of Kenya’s “hustler nation” — the disillusioned, mostly young strivers struggling to gain a foothold.
A question now hangs over the outcome because of the statement the vice chairwoman of the electoral commission, Ms. Cherera, made moments before the election results were announced. She said the four commissioners could not take ownership of the results because of the “opaque nature” of the election’s handling.
Later Monday, a spokesman for Mr. Odinga, Dennis Onsarigo, wrote on Twitter that the former prime minister planned to address the nation on Tuesday.
Supporters of Mr. Odinga began protesting after the announcement. In Kisumu County, a major stronghold for Mr. Odinga’s, hundreds of people began demonstrating and burning tires, witnesses said.
Mr. Odinga, who ran for president four other times, had been exceptionally critical of the vote-counting process even before the declaration of results.
“This was the most mismanaged election in Kenya’s history,” Saitabao Ole Kanchory, Mr. Odinga’s chief electoral agent, told reporters outside the national tallying center. He called the counting center in Nairobi “a crime scene” and said those in charge of the count “ought to be arrested.”
In a statement, the US Embassy in Nairobi applauded the “peaceful and orderly voting and counting process.” It called the declaration of Mr. Ruto’s victory an “important milestone in the electoral process” and urged the peaceful resolution of any remaining concerns.
The apparent defeat is a stinging blow for Mr. Odinga’s home region in western Kenya, as well as for his fellow Luos, the country’s fourth-largest ethnic group. Many Luos say that they have been unfairly excluded from the presidency since independence, and that Mr. Odinga was denied victory in 2007, when vote counting showed him leading before he was declared the loser.
That election led to violence in which more than 1,200 people were killed and tens of thousands of others fled their homes.
Declan Walsh and Matthew Mpoke Bigg reported from Nairobi, and Abdi Latif Dahir from Eldoret, Kenya.