The Independent Electoral and Boundaries Commission (IEBC) said Mr Kenyatta had won 50.07% of the vote, on a turnout of 86%.
However, supporters of his main rival, PM Raila Odinga, have alleged voting irregularities and indicated he would file a legal challenge.
Violence after the 2007 election left more than 1,000 people dead.
The IEBC said the latest elections had been complex and difficult but also credible and transparent.
It said the turnout was the largest ever.
IEBC chairman Issack Hassan said that Kenyans had voted “calmly, patiently, proudly and peacefully in the full glare of whole world”.
However, one of Mr Odinga’s aides said earlier that the candidate had “no intention” of conceding defeat.
Salim Lone told the Daily Nation newspaper: “The level of the failures in the system makes it very difficult to believe it was a credible result.”
Both candidates have complained of irregularities during the course of the count, since Monday’s election.
Mr Kenyatta won 6,173,433 votes out of a total of 12,330,028.
Mr Kenyatta’s Jubilee Coalition party said it was “proud and honoured for the trust” bestowed on it, adding that it had taken a message to the people and that “we are grateful to the people of Kenya for accepting this message”.
Early on Saturday, small groups of Kenyatta supporters celebrated in Nairobi, hooting car horns and singing.
But the newly confirmed president could face difficult relations with Western countries.
He faces trial at the International Criminal Court (ICC) in The Hague in July for crimes against humanity.
He is accused of fuelling communal violence after the 2007 election that saw more than 1,000 people killed and 600,000 forced from their homes.
Mr Kenyatta’s running mate, William Ruto, also faces similar charges.
Both men deny the accusations.
The ICC has agreed to postpone Mr Ruto’s trial by a month until May after his lawyers complained of not having enough time to prepare his defence.
Countries including the US and UK have hinted that his election as president would have consequences for their relations with the Nairobi government – comments which have been dismissed in Nairobi as unwanted foreign interference in domestic matters.
Kenya’s new electronic voting system was designed to eliminate the chance of vote-rigging and with it any risk of a repeat of the post-poll violence of 2007.
But the count has been plagued with technical glitches, including a programming error that led to the number of rejected votes being multiplied by a factor of eight. By Wednesday, the electronic system was abandoned and the count restarted by hand.
According to Kenya’s election rules, the winner needs to poll more than 50% of the vote to avoid a second round run-off next month.
If the election commission confirms that Mr Kenyatta has crossed the 50% threshold by such a narrow margin, then Mr Odinga’s officials say he will challenge the outcome.
The prime minister’s Cord alliance had earlier complained that votes from 11 constituencies were missing, in effect leaving him more than 250,000 votes short.
Both men passed a second condition needed for victory – at least 25% of the vote in more than half of the 47 counties.