Electoral Commission Chairman Samuel Kivuitu declared that Kibaki had garnered 4.5 million votes, beating out Raila Odinga by a little over 200,000 votes in what was the closest race in Kenya's history.
The result followed an electoral process that was originally dubbed the envy of Africa, but dissolved into chaos after violence broke out on Saturday over repeated delays in announcing the results.
Just an hour after the results were announced, Kenyan television showed Mr. Kibaki being sworn in for a second five-year term. He appealed for calm and promised a clean hands government.
In the Nairobi slum of Kibera, opposition candidate Odinga's stronghold, people took to the streets in protest after hearing the news. They were chanting "No peace! No peace!"
President Kibaki had seemed headed for defeat after early results showed Odinga with a one-million vote lead. Voters had also ousted many Kibaki allies and politicians tainted by corruption allegations in simultaneous parliamentary elections.
Earlier in the day, Election Commission Chairman Kivuitu had gone to announce the results, but had to be hustled off the stage when members of Odinga's Orange Democratic Movement began shouting in protest. He later announced the results from an office nearby.
Both Odinga and President Kibaki's camps had each accused the other side of massive rigging in the election. Kibaki ally Uhuru Kenyatta, who lost to Mr. Kibaki in the 2002 election, says that Odinga must now tell his followers to keep calm and avoid violence.
"What we are really concerned about is that our opponents rather than encouraging their supporters to remain calm are actually the ones who are inciting the violence in various parts of the country and that is tantamount to intimidation," Kenyatta said. "What if we were to do the same? What would this country be? So the key thing is that our opponents should tell their supporters to hold their horses, and let the legal constitutional process be completed."
Electoral observers had initially said the process was fair, but the delays in announcing the results led observers from the United States and the European Union to withhold their assessment. On Sunday, the European Union said its observers were blocked from the count.
After the results were announced, the European Union said that the electoral commission had failed to make the counting process credible, partly because it did not address evidence of possible vote-rigging that the European Union and electoral commissioners themselves have reported.
The commission said it had "some doubts" about the process and cited the case of the Molo constituency, where official results read out in the presence of the European Union had declared Mr. Kibaki the winner with 50,000 votes. However, in the tally read out by the electoral commission later, Mr. Kibaki was said to have captured 75,000 votes in that constituency.