* Kenyatta gets outright win with margin of 4,100 votes
* Rival Odinga fails to secure a run-off
* Kenyans waited five days to learn result
* Disputed election five years ago sparked tribal violence
By George Obulutsa and Edmund Blair
NAIROBI, March 9 (Reuters) - Uhuru Kenyatta, the son of Kenya's founding president, won the presidential election with a slim margin of 50.03 percent of votes cast, provisional figures showed, just enough to avoid a run-off after a race that has divided the nation.
Kenyatta, who faces international charges of crimes against humanity, secured victory over his main rival, Prime Minister Raila Odinga, who trailed with 43.28 percent of the vote.
To secure an outright win a candidate needed more than 50 percent of the votes. Kenyatta, the deputy prime minister, achieved that but with a margin of just 4,100 of the more than 12.3 million votes cast.
The first-round win, which must be officially confirmed by the Independent Electoral and Boundaries Commission, means Kenyans who waited five days for the result of the vote will not now face a second round that would have prolonged uncertainty.
The winner also needs to get at least 25 percent of the votes in 24 counties out of 47. This is expected be confirmed by the electoral commission. The commission is due to announce the official result on Saturday at 11 a.m. (0800 GMT).
But such a narrow win will almost certainly prompt legal challenges from Odinga's camp, which complained about the election process throughout. Odinga also lost in a disputed vote in 2007 that led to weeks of tribal killings.
John Githongo, a former senior government official-turned-whistleblower, urged the rival coalitions, Odinga's CORD and Kenyatta's Jubilee, to ensure calm. "Jubilee and CORD, what you and your supporters say now determines continued peace and stability in Kenya. We are watching you!" he said on Twitter.
International observers broadly said the vote and count had been transparent so far and the electoral commission, which replaced an old, discredited body, promised a credible vote.
Provisional figures displayed by the election commission showed Kenyatta won 6,173,433 votes out of a total of 12,338,667 ballots cast. Odinga secured 5,340,546 votes.
The result will pose a dilemma for Kenya's big Western donors because Kenyatta is due to go on trial in The Hague on charges of crimes against humanity, accused of orchestrating the tribal violence five years ago.
REBUILDING A REPUTATION
The United States and other Western states warned before the vote that diplomatic ties would be complicated with a win by Kenyatta who has been indicted by the International Criminal Court along with his running mate, William Ruto.
Western nations have given a broad range of views on how to deal with Kenya under Kenyatta and to what extent they will be ready to deal with his government.
"It won't be a headache as long as he cooperates with the ICC," said one Western diplomat. "We respect the decision of the majority of the Kenyan voters."
Both Kenyatta and Ruto deny the charges and have said they would cooperate to clear their names. However, Kenyatta had to fend of jibes during the campaign by his rival Odinga that he would have to run government by Skype from The Hague while he attended hearings.
Kenyans hope this vote, which has until now passed off with only pockets of unrest on voting day, would restore their nation's reputation as one of Africa's most stable democracies after mayhem last time.
Cars drove through the streets honking their horns, and one taxi driver shouted "50+1, that's OK," referring to the 50 percent plus one vote threshold required by law to win the vote, as noisy pockets of people yelled on the rainy streets.
The test will be whether any challenges to the outcome are worked out in the courts, and do not spill into the streets.
Odinga's camp had said even before the result that they were considering legal action, but said they would pursue it through the courts and the newly reformed judiciary.
That is a change from 2007, when Odinga said he could not trust the judiciary at the time to treat the case fairly.
Kenyatta's camp had also complained about delays in counting and other aspects of the process.
But many Kenyans had said this race was more transparent than previous votes. Turnout reached 86 percent of the 14.3 million eligible voters, in a nation where tribal loyalties largely trump ideology at the ballot box.
Kenyatta, comes from the Kikuyu tribe, Kenya's biggest ethnic community, accounting for about a fifth of Kenya's 40 million people, and Odinga, 68, is a Luo. Their ethnic groups alone could not have secured victory, so both picked running mates from other tribes to beef up their support. (Writing by Edmund Blair; Editing by James Macharia and Todd Eastham)