KIGALI, Rwanda — Kenya’s Supreme Court said on Wednesday that it had nullified last month’s presidential election because the voting may have been hacked, and accused the electoral commission of failing to verify results before announcing them.

It stopped short, however, of calling the vote rigged, and rejected the opposition’s assertion that President Uhuru Kenyatta had used state resources and undue influence to sway the outcome.

The commission had declared Mr. Kenyatta the winner of the Aug. 8 vote, with 54 percent of the ballots, to 44 percent for the opposition leader, Raila Odinga — a margin of about 1.4 million votes. Mr. Odinga challenged the result, and said that the last two elections had also been stolen from him.

The court’s rationale was narrowly tailored: It said the Independent Electoral and Boundaries Commission had announced the results prematurely, before it had received all the required forms tallying the results from polling stations.

The electoral body “cannot therefore be said to have verified the results,” said Philomena Mwilu, the deputy chief justice. She singled out the electoral commission chairman, Wafula Chebukati, for failing to explain why the results were not transmitted according to electoral rules.

“Elections are not only about numbers,” Justice Mwilu said. “Elections should be like a math test where you only get points for the answer if you show your workings.”

She also criticized the electoral commission for refusing to comply with court orders to open its computer servers, saying its refusal gave credence to opposition claims that the vote had been manipulated.

“This contemptuous disobedience with the court order leaves us with no option but to accept the petitioner’s claims that the I.T. system was infiltrated and the data therein interfered with,” she said. “Or officials themselves interfered with the data or simply refused to accept that it had bungled the transmission system and were unable to verify the data.”

The election controversy hinged on two paper forms used to legally validate the ballots — one from 40,883 polling stations and the other from 290 constituencies.

Representatives from rival parties were required to approve the forms before they were scanned and electronically transmitted to a national tallying center in Nairobi, where they were to be put online immediately so that they could be crosschecked.

But Therefore, only the results, and not the forms, were sent to the tallying center, often by text message.

The official results were based on the electronic tally, which was vulnerable to error, before the paper results were fully collated, the judges found.

In its findings earlier this month, the court also ruled that hundreds of polling stations had failed to send any presidential results; that some forms lacked security features like water marks, signatures or serial numbers; and that some unauthorized users had tried to access the voting system.

Kenya has been mired in political uncertainty since the election, and there are renewed fears of violence, even though the vote took place peacefully and there were far fewer deaths in its aftermath compared with previous polls.

The opposition leader Mr. Odinga has said he will refuse to participate in a new election unless electoral commission members are prosecuted and “legal and constitutional guarantees” are put in place to ensure a free and transparent vote.

This week, American and European observers cautioned political leaders and Kenyans against inciting violence as the country heads for a new election.

“Now is the time to focus on preparing for the new poll, which, in line with the court’s order and the Constitution, must be run by the Independent Electoral and Boundaries Commission and be held by the end of October,” the observers said.

Whether the new vote can be carried out by Oct. 17, as the court requested, is unclear. The French digital security company that supplied the voting technology says it has been treated unfairly and that the machinery probably will not be ready by that date.

The Sept. 1 ruling to nullify the election results came as a surprise, and has been seen as a milestone for the rule of law and for judicial independence on a continent where democratic norms are still in flux. A disputed presidential election a decade ago led to deadly violence, but this year’s voting was mostly peaceful.

Even so, the Kenyan judiciary said that judges and staff members had faced attacks and threats since the ruling and that the police had failed to adequately protect them.

“These attacks are denigrating, demeaning and degrading and are meant to intimidate, threaten and cow the institution and individual judges,” Chief Justice David K. Maraga said in a statement.

On Wednesday, security forces tear-gassed protesters who had gathered to demonstrate in front of the Supreme Court, and nearby roads had been blocked ahead of the much anticipated but contentious hearing.

Mai Hassan, an assistant professor of political science at the University of Michigan, called the developments “truly exciting.”

“The Supreme Court criticized the electoral commission’s handling of the election, and the lack of faith that it instilled in the citizenry, as opposed to flat-out arguing that the overall outcome — whether Uhuru ‘won’ — was in doubt,” she said. “In that way, this is a great step for Kenya. The judiciary is showing its might against the once all-powerful executive.”

She added that she expected Mr. Kenyatta, one of the richest men in Africa, to win a revote, but cautioned that she worried about the possibility of election-related violence.

“Now that there is another vote, I’m worried that Raila will rile up his supporters and Uhuru will respond with force,” she said. “Raila used a lot of war rhetoric in the run-up to the August vote, and Uhuru retaliated by being very clear that his government would not tolerate unrest.”