| Mr Ping supporters were chanting " Ali must go" |
Mr Bongo secured a second seven-year term with 49.8% of the vote to Mr Ping's 48.2 %, a margin of 5,594 votes. Mr Ping disputes the result. His camp has said figures from the president's stronghold showed a 99% turnout.
In 2009, the president took over from his father, who came to power in 1967.
Police have fired teargas to disperse supporters of Mr Ping who were trying to access the electoral commission headquarters in Gabon's capital, Libreville. The crowd was chanting "Ali must go" the AFP news agency reports.
There has been no independent statement from the electoral commission (Cenap), after Interior Minister Pacome Moubelet-Boubeya announced the results.
Delegates representing the opposition in Cenap walked out of the vote count and refused to sign papers validating Mr Bongo's victory, according to a BBC Afrique reporter in Libreville. Before entering politics Mr Ping was a renowned career-diplomat who served as the chairman of the African Union Commission.