In the prelude to this year’s vote, campaigns were dominated by concerns about the potential for vote rigging, and a senior election official in charge of voting technology, Christopher Msando, was killed.
The election was largely conducted in peace on Tuesday, with just a few technical glitches reported at polling stations.
But Mr. Odinga told a news conference in Nairobi, “The 2017 general election was a fraud.”
“The electoral fraud and fabrication of results was massive and extensive,” he said.
Preliminary results showed that with more than 90 percent of votes counted, Mr. Kenyatta was 10 percentage points ahead of Mr. Odinga, with a share of votes well ahead of the 50 percent needed to avoid a runoff.
Mr. Odinga said hacking had taken place between 12:37 p.m. and 4 p.m. on the day of the election. The hackers, he said, had used the credentials of Mr. Msando to instruct the servers of the electoral commission to doctor results from polling stations. “They loaded an algorithm which is a formula to create a percentage gap of 11 percent between our numbers,” he said, adding that the figure was “a function of a formula.”
Mr. Odinga, 72, who is running for a fourth time, said that his party’s tallying showed that he should be leading, although he refused to produce results to confirm that. He also declined to reveal the source of the hacking allegations.
Kura Yangu Sauti Yangu, a coalition of rights groups coordinated by the Kenya Human Rights Commission, said in a statement that the voting had been orderly, but that early results were “completely unverifiable” and that their publication risked “serious political instability.”
The coalition of rights groups cited as examples discrepancies between nationally announced figures and official written tallies made at five polling places. At one, in Nandi County, northwest of Kisumu, the group said that the local written tally had shown nine rejected votes and that the electoral commission had reported 439.
Andrew Limo, a spokesman for the Independent Electoral and Boundaries Commission, said that the body was collecting and matching so-called Form 34A documents — provided by each polling station detailing the results — with electronic data to check whether any manipulation had occurred.
“As of now, the commission has not found evidence of hacking,” Mr. Limo said, adding that matching the documents with the data would bring to light any potential “mischief” and that any discrepancies “would raise the alarm.”
The mood was tense in Kisumu, where residents said they were furious about what they called a hacked election.
Large parts of the city were calm, but in the Kondele neighborhood, crowds were being dispersed by police officers using tear gas.
Part of a nearby road was blocked, and tires had been set on fire. Some residents were seen running away.
“You cannot keep stealing votes at every election,” said Frank Opondo, 38, who was at the scene, while other people shouted, “No Raila, no peace!”
“The elections are not fair,” said Milama Obwanda, 37, as a crowd quickly formed around him. “We’re not going to relax until the decision we made yesterday is respected.”
His friend Doreen Atieno said that the hacking accusations and the killing of the election official needed to be investigated if the authorities and institutions in Kenya were to be trusted.
“We want to know,” she said. “We want leaders with clean hands. We’re not going to take it anymore.”
Throughout his campaign, Mr. Odinga stirred up supporters by warning that the election could be stolen. He said he had been robbed of victory in the previous two contests. In 2013, Mr. Kenyatta won by a margin so tiny that Mr. Odinga sought unsuccessfully to have the Supreme Court invalidate the election.
Fred Matiangi, the acting interior minister and a member of Mr. Kenyatta’s Jubilee Party, called on Kenyans to wait for the final results from the electoral commission. “Until then, we remain committed to do our part in ensuring that the country is secure and safe,” he told a news conference.
Mr. Matiangi said the government was not aware of postelection protests, and he asked Kenyans to resume their daily activities. “Be very careful of information that is bandied around on social media,” he added.