While recounts are not unprecedented in Gabon - the court ordered a recount that upheld Bongo's 2009 his victory - this may be the first time a court overturns a presidential election result in Africa.
The court refused to accept copies of vote tally sheets provided as evidence by Ping, many of which it said were illegible.
After two weeks of sporadic violence, Ping earlier this month told judges to choose between stability and instability when weighing their decision for the election result to be nullified.
Following the court ruling, President Bongo called for a "political dialogue" with the opposition.
Ping said that he had no faith in the court because of its ties to the president.
Ping, who officially lost by fewer than 6,000 votes, applied to the court to authorize a recount in the Haut-Ogooue province, Bongo's stronghold, where the president won 95 percent of the votes on a 99.9 percent turnout.
European Union election observers said there had been a "clear anomaly" in the results from the province.
Gabon's incumbent President Ali Bongo
The court's decision is likely to cause unrest in this oil-rich central African nation of some 1.8 million residents, where the same family has ruled since the 1960s.
With the country in political limbo for almost a month, concern had been growing that a ruling in favour of Bongo could spark a fresh wave of opposition protests. There were long queues at banks and supermarkets on Friday and the French embassy told its citizens to stay indoors.
"Judgement day" blared the headline in one newspaper, while another front page led with: "The hour of the last judgement is upon us". Immediately after the announcement of the results, deadly riots broke out in the capital and the country's national assembly was burned down.
Gabonese ministers, who have vowed to maintain order, warned 73-year-old Ping that he could be held responsible if fresh violence breaks out.
Ping has made clear he believes Bongo has the court in his pocket, referring to it as "the Tower of Pisa that always leans the same way".
In the chaos that erupted after the announcement, demonstrators set fire to the parliament and clashed violently with police, who launched a fierce crackdown arresting around a thousand people. The opposition says as many as 100 people died in the violence, while the government said three were killed.