NAIROBI — Kenya’s election commission on Saturday declared Uhuru Kenyatta, the son of Kenya’s first president and a suspect in a case involving crimes against humanity, the winner of the country’s presidential race amid growing allegations of vote fraud and a refusal by the other leading contender to concede.
Kenyatta, who has been accused by prosecutors at the International Criminal Court in The Hague of bankrolling death squads during Kenya’s last election crisis, cleared the 50 percent threshold and avoided a runoff by the thinnest of margins, about 8,000 votes out of 12 million, or 0.07 percent.
Kenyatta’s trial is set for July, which means that Kenya, one of the United States’s closest allies on the continent, could soon have a president commuting back and forth from The Hague, simultaneously trying to run a country and keep himself from being imprisoned for years.
Kenyatta has said he is innocent and that he will cooperate with the court, but in his acceptance speech on Saturday he signaled that he wanted the world to back off.
‘‘We recognize and accept our international obligations,’’ he said. ‘‘However, we also expect that the international community will respect the sovereignty and the democratic will of the people of Kenya.’’
Kenyatta, 51, a graduate of Amherst College and a confident speaker, said Kenya had surpassed expectations. “We dutifully turned out, we voted in peace, we upheld order,’’ he said Sunday. ‘‘That, ladies and gentlemen,’’ he emphasized, ‘‘is the real victory.’’
But it is not clear whether Kenya’s election is really over. The second-place finisher, Raila Odinga, Kenya’s prime minister, has refused to admit defeat and plans to appeal to Kenya’s Supreme Court to overturn the results, which some independent observers said were suspicious.
Odinga said there had been ‘‘rampant illegality’’ and ‘‘massive tampering’’ with the vote-tallying process, the same problem that happened in 2007 during Kenya’s last election. Odinga narrowly lost that vote, and Kenya exploded in political violence.
‘’We thought this would never happen again,’’ he said, referring to the fraud allegations.
But he urged his supporters to stay calm. ‘‘We don’t want riots, property damage, or any other kind of disturbance,’’ Odinga said. ‘‘Any violence now could destroy this nation forever.’’
Some of Odinga’s strongholds, like the sprawling Kibera slum, were tense on Saturday. Police officers in helmets patroled the streets as groups of young men glared at television sets, many still visibly dumbfounded by the election results, but there were no reports of major violence.
Kenyatta’s victory, after a heated race, poses unique challenges for the Obama administration, which increasingly relies on Kenya as a strategic partner in a volatile region, yet, at the same time, has pledged to support the International Criminal Court, though the United States is not a member.
In the weeks before the election, the top US official for Africa issued a thinly veiled warning that ‘‘choices have consequences’’ and some Western diplomats here indicated that they would keep their distance from Kenyatta, currently a deputy prime minister, should he win.
Many analysts predict that the coming months will be an awkward time for US-Kenya relations, unexpected, perhaps, considering that Kenya was the birthplace of President Obama’s father and a place Obama has written fondly about.
The International Criminal Court — and the perception that Western countries were lining up against Kenyatta — seems to have been a galvanizing factor in this election, driving Kenyatta’s supporters to the polls in a tsunami-like force.
‘‘Kenyans may be tribalists but we are also nationalists,’’ said Edward Kirathe, a real estate developer and a passionate Kenyatta supporter.
Kenyatta’s running mate, William Ruto, who is in line to become deputy president, has also been charged by the International Criminal Court with crimes against humanity, accused of sponsoring gangs that hunted down supporters of his political opponents in 2007 and early 2008.