In the run-off vote on December 19, Andry Rajoelina took 55.7 percent and Marc Ravalomanana won 44.3 percent, according to the final results.
Madagascar's Constitutional Court on Tuesday confirmed Andry Rajoelina as the winner of the country's presidential election after his opponent lodged a complaint alleging fraud.
"Andry Rajoelina is declared the elected president of the republic," said Judge Jean-Eric Rakotoarisoa, triggering celebrations among supporters gathered in the capital Antananarivo.
Ravalomanana had complained of widespread fraud and petitioned the Constitutional Court, which threw out his case as "unfounded."
Both contenders attended the court ruling but left without commenting.
Last week riot police in the Indian Ocean island used tear gas to break up one of several protests by thousands of Ravalomanana supporters.
The bitter rivals, both former presidents, were banned from running in the 2013 election as part of an agreement to end recurring crises that have rocked Madagascar since it gained independence from France in 1960.
Both sides alleged fraud in the two-round election, and a contested result may raise the risk of renewed political instability.
European and African Union election observers said they had not seen any evidence of significant wrongdoing.
TRT World's Francis Collings reports.
Fiercely personal duel
Rajoelina and Ravalomanana have been locked in a fiercely personal duel for power, coming first and second in the first-round vote in November.
Ravalomanana, 69, was first elected president in 2002 but was forced to resign seven years later by violent demonstrations supported by Rajoelina, then the mayor of Antananarivo.
Rajoelina, now 44, was installed by the army and ruled until 2014. He is a former events planner and successful entrepreneur with slick communication skills.
Both candidates spent lavishly on campaigning, with promises and handouts distributed liberally to voters, who are among the poorest in Africa.
Madagascar is well known for its vanilla and precious redwood but is one of the world's poorest nations, with 76 percent of people living in extreme poverty.
The island, which is also famed for its unique wildlife, is dependent on foreign aid and burdened by political friction.
"Most people want reconciliation," said former education minister Paul Rabary, a candidate who was eliminated in the first round.
Political analyst Sahondra Rabenarivo added that "everyone wants to turn the page" after the fractious election process.
Rajoelina will be inaugurated as president on January 25.
Outgoing president Hery Rajaonarimampianina was eliminated in the first round after collecting less than nine percent of the vote.
His attempts to change the electoral laws this year backfired, sparking nearly three months of sometimes violent protests.
The demonstrators forced Rajaonarimampianina to accept a "consensus" government tasked with organising the election.