The six-judge Supreme Court panel found no misconduct on the part of the president, Mr. Kenyatta, but it found that the commission “committed irregularities and illegalities in the transmission of results” and unspecified other issues.
“Irregularities affected the integrity of the poll,” Justice Maraga told a stunned courtroom.
A new vote would mean that candidates would have to start campaigning again and raise millions of dollars: Elections in Kenya generally cost about $1 billion, including spending by the candidates during the campaign and by the government to hold the vote.
Thousands of people in the opposition strongholds of Kisumu, Mombasa, and parts of Nairobi streamed into the streets and whooped with joy after the news was announced, while supporters of Mr. Kenyatta in Gatundu, his hometown, were subdued.
“I am happy to be Kenyan today,” said Mr. Odinga, a former prime minister in his fourth run for the presidency. “It is a historic day for the people of Kenya, and by extension the people of Africa.”
It was the first time in the history of African democratization that “a ruling has been made by a court nullifying irregular presidential elections,” he said. “This is a precedent-setting ruling.”
The National Democratic Institute, a nonpartisan organization that supports democratic institutions and practices worldwide, said that it was the first example in Africa in which a court nullified the re-election of an incumbent.
Mr. Odinga said his team planned to take members of the electoral commission to court, saying that they had “committed a criminal act” and belonged in jail.
Mr. Kenyatta said he respected the ruling and called on all Kenyans to respond peacefully, but he also made clear his anger toward the court. “Millions of Kenyans queued, made their choice, and six people have decided that they will go against the will of the people,” he said.
Security had been increased on Friday in opposition strongholds, amid concern that a ruling in favor of either side could…