In 2005, voters shot down Kibaki's constitution draft, handing the two rivals a victory.
However, the two parted ways before the last election in 2007.
Kenyatta, who was not running for office then, threw his weight behind Kibaki, who was up against Odinga.
He later served in various positions in Kibaki's government, including finance minister and his latest role, deputy prime minister.
After the 2007 election
The last election stoked deep ethnic rivalries.
When Kibaki was declared the winner, Odinga alleged the vote was rigged, sending supporters battling on the streets.
The International Criminal Court has indicted Kenyatta for allegedly funding a local militia that conducted reprisal attacks at the time.
He has denied the charges, and vowed to cooperate with the court to clear his name.
His running mate William Ruto and two others are also indicted.
Kenya reneged on a deal to try the perpetrators in local courts, forcing the courts to step in.
A Western quandary
Before the 2013 election, Johnnie Carson, the top American envoy to Africa, warned that "choices have consequences," widely interpreted as a threat to Kenyans not to vote for him.
Carson's predecessor, Jendayi Frazer, slammed his stance against Kenyatta, describing it as "reckless and irresponsible."
"Kenyatta knows that he needs the United States, and the United States knows it needs Kenya," Frazer said. "While it (relations) might be awkward, there won't be a significant change in our policy stances toward Kenya or theirs toward us."
In a statement after the election, U.S. Secretary of State John Kerry applauded the vote -- but did not mention Kenyatta.
"We ... will continue to be a strong friend and ally of the Kenyan people," he said.
Kenyatta has said the indictment will not affect his ability to do his job and urged the international community to respect the will of Kenyans.
Analysts say the ICC indictment may have rallied citizens to Kenyatta's side in defiance of the West.
A majority of the court's investigations are focused on African nations.
"Many Africans have lost faith in ICC and view it as targeting African leaders and failing to discharge its justice among non-African leaders," Johnson said.
Kenyatta's trial is scheduled for July, while his running mate's is in May.
Kenya will become the second African nation after Sudan to have a sitting president facing charges at the International Criminal Court.