However the 44-year-old former events planner was not declared president after Ravalomanana lodged complaints with the court about alleged widespread fraud.
Those were rejected following a two week investigation.
"Andry Rajoelina is declared the elected president of the republic," said Judge Jean-Eric Rakotoarisoa.
His announcement sparked celebrations among Rajoelina's supporters in the capital Antananarivo.
Rajoelina and Ravalomanana - both former presidents - were banned from running in the 2013 election under an agreement to end recurring crises that have plagued Madagascar since it gained independence from France in 1960.
Ravalomanana, 69, was first elected president in 2002 but was forced to resign seven years later following violent demonstrations supported by Rajoelina, then the mayor of Antananarivo. Rajoelina was installed by the army and ruled until 2014.