An AFP photographer saw one of the victims, a young man with a massive gunshot wound to the head, while a senior police officer confirmed two had been killed in the flashpoint slum of Mathare.
"They were part of a group that was protesting in the area and officers were sent to quell the chaos," the officer said on condition of anonymity.
"We are told many of them were also thieves who took advantage and could not even obey the police. Two have been fatally wounded."
Japheth Koome, police chief for Nairobi, said the two who were killed had tried to "attack our officers with pangas (machetes) and that's when the officers opened fire on them."
An AFP photographer saw a bloodied machete lying on the ground at the scene of the unrest.
Police fired teargas -- and in some cases live bullets into the air -- to disperse several protests, which erupted in opposition strongholds in Nairobi as well as the western city of Kisumu after Odinga claimed a massive hacking attack had manipulated electronic tallying results.
Kenyatta looked to have an unassailable lead, according to unofficial results streamed onto the election commission (IEBC) website, handing him 54 percent compared to Odinga's 44.7 percent, with votes from over 96 percent of polling stations counted.
The bloodshed comes a decade after a disputed poll, which Odinga lost to former president Mwai Kibaki, led to two months of clashes that left 1,100 people dead and 600,000 displaced.
Decrying a "sham" tallying process, Odinga detailed accusations of a major attack on the electronic system, saying hackers had gained entry using the identity of top IT official Chris Msando, who was found murdered and tortured late last month.
"This is an attack on our democracy. The 2017 general election was a fraud," said Odinga, claiming detailed evidence of the hackers' movements.
The 72-year-old, who is making his fourth bid for the presidency as the flagbearer for the National Super Alliance (NASA) coalition, accused his rivals of stealing victory from him through rigging in 2007 and in 2013.
"You can only cheat a people for so long," he said.
'Free and fair'
IEBC chairman Wafula Chebukati insisted the poll was "free and fair".
"As a commission we shall carry out investigations to establish whether or not the (hacking) claims are true," he said, adding that the IEBC had a week to release final results.
Raphael Tuju, secretary-general of Kenyatta's Jubilee party, urged the opposition to "look at the figures soberly" and accept the results.
"You cannot claim that results are fake with respect to presidential vote and you welcome the areas where your governors and MPs have won convincingly. You have to accept the results however they come," he said.
Odinga urged his supporters to "remain calm as we look deep into this matter." But he added: "I don't control the people."
As his speech ended, scores of supporters gathered in Kisumu and Mathare, burning tyres, setting up barricades and engaging in running battles with riot police.
"If Raila is not president, we can't have peace," one Kisumu protester told AFP.
Resident Geoffery Omondi, 22 shook his head as protesters lit a new fire nearby. "It is very painful to watch. The problem is the IEBC who did not announce results well."
However the protests remained isolated, and in opposition strongholds where elections tend to stoke tensions.
Nevertheless the normally traffic-choked streets of Nairobi remained deserted as the country held its breath over the results.
The contest between Odinga and Kenyatta was seen by pollsters as too close to call ahead of the vote.
It is the second time the two men have faced off in a presidential election, a dynastic rivalry that has lasted more than half a century since their fathers Jomo Kenyatta and Jaramogi Odinga went from allies in the struggle for independence to bitter rivals.
The men belong to two of Kenya's main ethnic groups, Kenyatta from the Kikuyu, the largest, and Odinga from the Luo.
Both had secured formidable alliances with other influential communities in Kenya, where voting takes place largely along tribal lines.
In 2013 Kenyatta won by 800,000 votes.
Kenyatta, 55, is credited with overseeing steady economic growth of more than five percent. However food prices have soared under his watch and several major corruption scandals broke out in his first term.