The atoll nation’s joint opposition welcomed the surprise ruling, which has also granted them a parliamentary majority and stunned the government of strongman President Abdulla Yameen.
“The Supreme Court’s verdict effectively ends President Yameen’s authoritarian rule,” the opposition said in a statement calling for his resignation.
The Maldives’ popular image as an upmarket holiday paradise had been severely damaged by a major crackdown on dissent under Yameen, who has overseen the jailing of almost all the political opposition.
Yameen’s spokesman, Ibrahim Hussain Shihab, said the court had made its decision without hearing out the government.
“While the ruling makes significant implications on various points of constitutional import and criminal justice procedures, it was issued without representation of the state from either the Attorney General or the Prosecutor General,” Shihab said in a statement.
However, he said the administration “will work to engage, and consult with, the Supreme Court in order to comply with the ruling in line with proper procedure and the rule of law.”
On the tiny streets of the capital Male, there were celebrations. Hundreds of opposition activists took to the streets and were quickly pushed back by police who fired teargas.
Nasheed, who is currently in neighboring Sri Lanka, urged his supporters to avoid confrontation with the police.
“President Yameen must abide by this ruling and resign,” Nasheed said on twitter. “Urge all citizens to avoid confrontation and engage in peaceful political activity.”
Nasheed, who is living in self-imposed exile, was sentenced to 13 years in jail on a terrorism charge widely criticized as politically motivated.
In its order, seen by AFP, the Supreme Court said the “questionable and politically motivated nature of the trials of the political leaders warrant a retrial.”
The court ordered authorities to immediately free nine jailed leaders.
The Maldives police said in a tweet that it will abide by court orders, but within minutes the government announced the sacking of police chief Ahmed Areef.
Attorney General Mohamed Anil told a hurriedly summoned press conference at the military headquarters in the capital that Yameen sacked the police chief because he was uncontactable after the court order.
Anil said they were also in the process of “verifying the validity” of the court order.
The court also restored 12 dissident members of parliament who had been controversially expelled in July for defecting from Yameen’s party. The latest order gives Yameen’s opponents a majority in the 85-member parliament.
Earlier this week, opposition figures jointly petitioned the court to remove Yameen over alleged corruption.
Opposition figures including Nasheed and another five dissidents named in Thursday’s order have united against the president.
Among those who petitioned the top court was Yameen’s half-brother and former president Maumoon Abdul Gayoom, whose legislator son, Faris Maumoon, had been arrested. He was among those whose release the court ordered.
Also among them is Ahmed Adeeb, Yameen’s erstwhile deputy, who is serving a 15-year jail term after being convicted on a charge of attempted assassination in September 2015.
Another key dissident, Qasim Ibrahim, who helped Yameen in the 2013 run-off election, was also ordered to be released.
He, however, is not in the Maldives. Like Nasheed, he also obtained prison leave for medical treatment and has remained in Europe.
Almost all key opposition leaders and a number of ruling party dissidents have either been jailed or gone into exile in the Maldives in recent years under Yameen.
The president took office in 2013 after winning a controversial run-off vote against Nasheed.
The former president was jailed in 2015, but granted prison leave in 2016 for medical treatment in London, where he secured political asylum.
Last year he announced his intention to return and run for president in elections due later this year, but he was prevented by the criminal conviction against him.
The United States has said democracy is under threat in the strategically located archipelago of 340,000 Sunni Muslims, which sits on key international shipping lanes.