Nasheed, 50, the country's first democratically-elected leader, was sentenced to 13 years in jail on terror charges in 2015 over the arbitrary arrest of chief criminal judge Abdullah Muhammed during his presidency.
The UK granted him asylum after he was authorised to seek medical treatment there amid mounting foreign pressure.
The ruling by the Supreme Court came yesterday during the hearing of a petition by the joint opposition which had sought the removal of President Yameen, alleging corruption, misrule and rights abuses.
The apex court also reinstated 12 members of parliament who had defected to the Opposition and lost their seats last year.
More From This Section
Nasheed, who is among the prisoners ordered freed, said in a tweet: "Welcome tonight's SC ruling calling for the immediate release of political prisoners and the restoration of their civil and political rights. President Yameen must abide by this ruling and resign. Urge all citizens to avoid confrontation and engage in peaceful political activity".
The Supreme Court ruling also stated that political pressure was put on the prosecutors and the courts during the trials, the MDP claimed.
Hundreds of MDP supporters celebrated the judgment in Male while demanding Yameen's impeachment.
It was not immediately clear when the political leaders would be released from the prison.
While President Yameen's term in office will end in November this year, according to the Constitution, the presidential elections are to be held in August.
The Maldivian government holds that Nasheed is convicted for a crime and is wanted in the Maldives to serve a jail sentence. Nasheed said he will seek UN support to ensure he is allowed to contest.