Mr Odinga said the ruling marked “a historic day for the people of Kenya and by extension for the people of the continent of Africa”.

He added that he had “no faith at all in the electoral commission as currently constituted” and called for the prosecution of its members.

A lawyer for President Kenyatta said the decision had been “very political” but had to be respected.

A huge victory for Odinga – by Dickens Olewe, BBC News

Raila Odinga will feel vindicated against accusations that he was just being a bad loser in challenging President Kenyatta’s win.

However, this historic decision is a massive indictment of the electoral commission. It is therefore no surprise that the opposition Nasa coalition is now calling for a new team to manage the next elections.

This is also a setback for the international, and some local, election observers, who profusely praised the election as free, fair and credible.

People will be watching for the reaction of former US Secretary of State John Kerry, who was the head of the mission for US NGO The Carter Centre, whose positive assessment of the election was used in court.

Regardless of the winners and losers following the ruling, this is a proud moment for Kenya. The litigation and debate on the merits of the election was done at the Supreme Court and not on the streets.

Chief Justice Maraga said it best in his opening statement: “The greatness of a nation lies in its fidelity to the constitution and the strict adherence to the rule of law.”