As smoke rose over parts of Nairobi, the capital, Kenya's emerging democracy also appeared to be smoldering. Before the chaotic count, which saw election officials leave and European Union observers turned away without access to tallies, analysts and diplomats had viewed Kenya as one of the most promising democracies in Africa.
But the politics of the Big Man still hold sway in many parts of Africa, where only a few presidents have lost power through the ballot box.
After the 76-year-old president was sworn in for another five-year term, his challenger, opposition leader Raila Odinga, wiped away tears as he said a ruling clique was trying to rob Kenya of its democracy.
Odinga, 62, said he would be sworn in as the "people's president" in his own ceremony today and outlined plans for a parallel government. As he spoke, live television transmissions were cut.
There were reports of violence across the country. In Kibera, a Nairobi slum area and opposition stronghold, thousands of protesters armed with rocks, knives and machetes chanted, "No peace!"
Rampaging mobs burned shacks and kiosks and beat people up. Panic-stricken people fled the area, shouting that gangs of youths were stoning cars and attacking and robbing people. Police fired tear gas and live bullets to try to disperse the protesters.
But in Kibaki's strongholds, his supporters danced and sang.
The violence ran along tribal lines, as opposition supporters from the Luo tribe attacked those from Kibaki's Kikuyu tribe. Local media reported at least 13 people dead, including several protesters shot by police. At least 70 had died in earlier election-related violence.
According to the official result, Kibaki won 4,584,721 votes and Odinga had 4,352,993. Odinga was well ahead in counting Friday, but Saturday saw the tally steadily tilt in Kibaki's favor, triggering riots across Kenya.
"Kenyans will not accept the results of a rigged election," Odinga, the leader of the Orange Democratic Movement, had declared Sunday. "No force will stop Kenyans attaining what they want."
He said his party's figures indicated the election had been rigged by 300,000 votes.
The parliamentary vote, also held Thursday, had shown a massive repudiation of the government. Twenty government ministers lost their seats.
The chief of the European Union election observers in the country, Alexander Graf Lambsdorff, reported evidence of irregularities.
"We regret that it has not been possible to address irregularities about which both the Election Observation Mission and the Electoral Commission of Kenya have evidence," he said in a statement Sunday, adding that "some doubt remains as to the accuracy of the result of the presidential election as announced today."
A welder, Michael Mulama, 47, of Nairobi, said he was dismayed and puzzled by the result. "Why has Mzee done this?" he said, using a Kenyan nickname for Kibaki that means wise old man. "Is the government happy when people are dying? This is really bad."
But at the swearing-in ceremony, just an hour after the result was announced, Kibaki insisted that the election was free and fair, and called for reconciliation and healing.
"I urge all of us to set aside the passions that were excited by the election process, and work together as one people with the single purpose of building a strong, united, prosperous and equitable country," he said.
Kenya is usually a haven of stability in one of the continent's most volatile regions. But tribalism determines voting patterns and often erupts into violence.
In the lead-up to elections in 1992, 2,000 people died in tribal violence.
Political analyst Robert Shaw said there was clear rigging of the vote, in a serious setback for Kenyan democracy. He predicted a period of instability and unrest.
"I think the presidential result is a complete fraud. We are going to see a lot of turmoil and a lot of questions being asked," he said. But he predicted that Kibaki's effort to hold on to power would fail.
"There was deliberate rigging, but the overall momentum for democracy in Kenya will not accept that. I don't think the status quo, in terms of Kibaki being accepted as president, will be sustained."
Scuffles broke out as the chief of the electoral commission, Samuel Kivuitu, read the final results.
As he read the result for one constituency, opposition agents shouted angrily and one opposition representative approached Kivuitu yelling, "Justice! This is not a police state!"
Dozens of paramilitary police flooded in and escorted Kivuitu from the room. Soon afterward, he appeared live on television and declared Kibaki the winner.
Throughout Kenya, opposition supporters reacted with disappointment and anger to Kibaki's victory.
"I am disappointed," said Joshua Owino, 32, a security guard in Nairobi. "I know Kenyans voted strongly for change and it has been denied. This leadership is an indirect dictatorship."
Immaculate Kieti, 37, a shopkeeper, predicted there would be a period of violence, but not civil war.
"Kenyans will not fight for real, but there is going to be some unrest and chaos due to the emotion," she said. "But Kenyans will not be intimidated. Raila remains our president."
Under Kibaki, Kenyans have enjoyed stable economic growth, a booming tourist industry and free elementary school education, but his opponents say he did not deliver on his promise to deal with corruption, a big issue for voters.
Odinga, the son of the country's first vice president, is a wealthy businessman who promised to improve the lives of the poor.
Special correspondent Soi reported from Nairobi and Times staff writer Dixon from Johannesburg, South Africa.