Throughout his campaign, Mr. Odinga roused supporters by warning that the election results would be manipulated. As ballots were being counted, he claimed that the electoral commission’s servers had been hacked — which he linked to the poll official’s death — to award Mr. Kenyatta a significant lead. Then, the opposition leader asserted that he had obtained secret information from the electoral body showing him to be the real winner.

So far, Mr. Odinga has not provided evidence supporting those allegations.

But tensions were ratcheted up when he refused to concede defeat, saying that the electoral commission had not properly addressed the opposition’s grievances before officially announcing the winner. He has urged his followers to remain calm, but he also said he did not “control the people.”

At the same time, top opposition officials have indicated that they are unwilling to resolve their concerns about election fraud in court, as they tried, unsuccessfully, to do after the 2013 election. Election observers warned that such comments could be interpreted by the opposition’s supporters as a call to protest. Many did.

Shortly after the announcement of Mr. Kenyatta’s victory was televised, riots erupted in major cities across Kenya. They were mostly in poor areas that are generally neglected by the central government, and where residents suffer from high unemployment and rising living costs. Many cannot afford to buy ugali, a staple food, or pay school fees for their children. “We are hungry and angry,” said a Kisumu resident, Steve Odundo, 22.