Supporters of Kenya's President Uhuru Kenyatta hold posters and blow vuvuzelas as they await an expected announcement of election results in downtown Nairobi on Friday. (Brian Inganga/AP)

Kenya’s electoral commission announced Friday that President Uhuru Kenyatta has been elected to a second term, putting an official end to a fierce electoral contest that many fear could still be clouded by a dispute over the results.

Opposition candidate Raila Odinga, 72, has alleged that the results of Tuesday’s balloting were rigged and pledged not to accept them unless he was declared the winner. That stance has raised tensions, with Odinga’s followers burning tires in recent days in some of Nairobi’s slums and protesting in the western city of Kisumu.

Some of Odinga’s campaign officials on Friday suggested a possible way out of the dispute, saying they might accept the results if they were able to inspect the electoral commission’s computer servers. But Odinga did not concede and later refused to participate in the official announcement of the result. For days, some of his most extreme supporters have promised to take to the streets if Kenyatta was announced the ­winner.

“We will not be party to [the announcement]. Our issues have not been addressed,” said Musalia Mudavadi, one of Odinga’s ­advisers.

According to the official results, Kenyatta received 54.2 percent of the votes to Odinga’s 44.7 percent.

Bystanders watch as Kenyan police trucks arrive following a protest at Nairobi’s Mathare slum. (Luis Tato/AFP/Getty Images)

This week, Nairobi, normally a frenetic city of legendary traffic jams, was transformed into a relative ghost town, with many families leaving out of fear. On Friday morning, in anticipation of the official results being announced, Odinga’s supporters staged small demonstrations in some areas, taunting the police and chanting “No Raila, no peace.”

Even though Kenya has been considered a model of political and economic stability in East Africa in recent years, it is riven by tribal loyalties. In 2007, more than 1,000 people were killed in ethnic violence after Odinga lost that year’s presidential election amid alleged vote-rigging.

In an acceptance speech Friday, Kenyatta told his opponents: “We are not enemies. We are all citizens of one republic.” He later added, “There is no need for violence.”

Kenyatta, 55, the son of Kenya’s first president, Jomo Kenyatta, is a member of the Kikuyu ethnic group, which has dominated politics since the country’s independence from Britain in 1963. Odinga, his longtime rival, belongs to the Luo tribe.

Kenyatta has tried to project the image of a reformer, even as his government has been plagued by allegations of corruption.

In his second term, he will govern a nation where economists see potential for growth, but where the challenges facing public institutions — from the security forces to the health sector — are profound. Although Kenya is a vibrant democracy, most people in the country lack faith in their own government’s ability to assist them.

One of the reasons, analysts say, that Kenya’s elections are so hotly contested is that the central government has been an enormously profitable political machine, awarding contracts across a large patronage network. A report from Kenya’s auditor-general last year said that about $200 million meant for the National Youth Service had been paid to fraudulent companies, including some with connections to politicians. The United States earlier this year suspended $21 million in health funding due to corruption allegations.

In the days since the presidential vote, Odinga has put forth two hazy explanations about how the vote was manipulated.

He first alleged that a hacker had gained access to the electoral commission’s database and then accused the commission of concealing the actual results, which Odinga said proved he was the winner.

Election monitors, including former secretary of state John F. Kerry, said they saw no signs of a rigged vote.

But Odinga supporters, many of them members of his Luo tribe or its allies, said they are being robbed of yet another election. The Luo are one of the major ethnic groups in Kenya, but a Luo has never been president.

“We are tired of being ruled by Kikuyus,” said Wycliffe Onyalo, 25, who was demonstrating in favor of Odinga on Friday morning in Nairobi’s Kibera slum, before the results were announced.

“We are willing to lose our lives,” said Steve Omindo, another protester.

Kenya was caught largely ­unprepared for the post-election violence that erupted in 2007. This time, security forces fanned out in volatile parts of the country. ­Analysts expected faceoffs between protesters and police in places like Kibera, but said the violence would not likely consume entire cities and towns as it did a decade ago.

Kenyatta was charged by the International Criminal Court with instigating some of the violence in 2007. Those charges were later dropped for lack of evidence .

Rael Ombuor in Nairobi contributed to this report.