Nairobi, Kenya (CNN) -- Uhuru Kenyatta, the son of Kenya's founding leader, narrowly won the presidential poll despite facing charges of crimes against humanity over election violence five years ago.
Kenyatta clinched 50.07% of the vote, the election commission announced Saturday, barely breaking past the halfway mark.
His main rival, Prime Minister Raila Odinga, got 43.31% of the vote, and said he will challenge the outcome in court.
The constitution requires a 50% plus one vote for an outright win.
His victory puts the West in a quandary. Kenyatta is facing trial at the International Criminal Court over post-election violence that plunged the nation into chaos in 2007.
Shortly after election officials announced the results, he thanked citizens for bestowing him the leadership role and vowed to work for everyone.
"We celebrate the triumph of democracy; the triumph of peace; the triumph of nationhood," Kenyatta said. "Despite the misgivings of many in the world, we demonstrated a level of political maturity that surpassed expectations."
Winning parties should remain "modest in victory," he said, acknowledging that nearly half the nation did not vote for him.
Jubilant supporters took to the streets, speeding down crowded streets, honking and chanting his name.
"This is a new dawn, our leader has been elected," said John Kamau, a Nakuru resident.
'It is frustrating'
For some of Odinga's strongholds, the mood was tense but calm.
"Our man has tried to be president three times, it is frustrating," said James Ouma, who lives in the capital of Nairobi. "We will accept it. What can we do? Life must go on."
Odinga said the election outcome is flawed.
"We are confident that the court will restore the faith of Kenyans in the democratic role," he said.
Despite the looming challenge, Kenyatta struck a conciliatory note after the close election, applauding Odinga for a "spirited campaign,"
"I know that all the candidates have made tremendous personal sacrifices .. and I welcome them to join us in moving our nation forward," he said.
A vital ally
The vote's significance extends far beyond Kenyan borders.
Kenya is East Africa's biggest economy and a crucial trade route into the rest of the continent.
It provides an important buffer of stability in a region that includes the fledgling Somali government and the politically tense Sudan and South Sudan.
Most importantly -- at least to the West -- Kenya is a major U.S. ally in the war against Islamist militants in the region and has remained relatively peaceful amid civil wars in neighboring nations.
Kenyatta's victory raised the prospect of complicated diplomatic ties with the West.
The International Criminal Court indicted him for allegedly funding a local militia that conducted reprisal attacks in the last election in 2007. His running mate, William Ruto, also faces ICC charges at The Hague.
Both have denied the charges and have said they will cooperate with the court to clear their names.
The assurance has not allayed fears among some Western diplomats.
Before the election, Johnnie Carson, the State Department's top diplomat for Africa, issued a stern warning, saying Kenyans can pick their own leaders, but "choices have consequences."
But in a statement after the election, U.S. Secretary of State John Kerry applauded the vote.
"Kenya has been one of America's strongest and most enduring partners in Africa," Kerry said. "We ... will continue to be a strong friend and ally of the Kenyan people."
The UK minister for Africa, Marks Simmonds, echoed his sentiment and called on candidates to address disputes in court to avoid violence.
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.
"I have been a member of the government, and I've still been able to execute my duties," said Kenyatta, a deputy prime minister in the outgoing administration. "I still believe I will be able to execute my duties as president."
Carson's predecessor, Jendayi Frazer, said she does not foresee much change in ties between Kenya and the United States.
"Kenyatta knows that he needs the United States, and the United States knows it needs Kenya," she said. "And so I suspect that while it might be awkward, there won't be a significant change in our policy stances toward Kenya or theirs toward us."
No faith in the ICC
Analysts say the ICC indictment may have rallied citizens to Kenyatta's side in defiance of the West.
"Many Africans have lost faith in ICC and view it as targeting African leaders and failing to discharge its justice among non-African leaders," said Ayo Johnson, director of ViewPoint Africa. "Kenya sent a loud message to the ICC ... don't interfere. And it does not matter if you brand our leaders as criminals."
The president-elect's trial is scheduled for July while his running mate's is in May.
Kenya is the second African nation after Sudan to have a sitting president facing charges at the International Criminal Court.
Eager to avoid a repeat
In a nation with fierce ethnic loyalties, Kenyans were eager to avoid a repeat of the last election.
At the time, the nation plunged into ethnic violence after Odinga disputed results that declared the incumbent president, Mwai Kibaki, as the winner, alleging the election had been rigged.
Ethnic groups loyal to each side took to the streets, where supporters of both camps fought one another. More than 1,200 people were killed and hundreds of thousands displaced.
But despite the divisive vote this year, some citizens said it is time to move forward.
"The people have spoken, even though my voice was not one of them," said Jane Nduku, a Nairobi resident.
Kenyatta's win at age 51 makes him the nation's youngest president.
CNN's Nima Elbagir reported from Nairobi, and Faith Karimi from Atlanta. CNN's Lillian Leposo contributed to this report.