A court in the Maldives has thrown out a "terrorism" conviction against the island nation's former President Mohamed Nasheed, and ordered the release of several other jailed politicians.

The Supreme Court ruling on Thursday came after an opposition alliance petitioned the top court to temporarily remove President Abdulla Yameen for misrule, rights abuses and "unprecedented corruption".

Judges did not rule on that request, but instead ordered the release of a total of nine people they said were jailed in unfair trials.

The court also reinstated 12 parliament members who were stripped of their seats when they defected to the opposition last year.

That gives the opposition a clear majority in the parliament, which has the power to impeach the president.

The main opposition Maldivian Democratic Party (MDP) hailed the ruling, describing it as a "death knell for President Yameen's corrupt and criminal dictatorship".

Yameen, 58, assumed office in 2013 after winning a controversial runoff against Nasheed.

His presidency has been marked by political intrigue, turmoil, and allegations of corruption, which have dented the Maldives' image as a tourist paradise.

The unrest began in 2015 when Nasheed, the country's first democratically elected leader, was jailed on "terrorism" charges relating to the arrest of a judge during his tenure.

The trial, declared unfair by the UN, prompted widespread protests and resulted in the arrest of hundreds of dissidents.

Since then, almost all key opposition leaders have either been jailed or gone into exile. In 2016, Nasheed also sought political asylum in the United Kingdom after traveling there on medical leave from prison.

Reacting to the developments in Male on Thursday, Nasheed said he welcomed the Supreme Court's decision and urged Yameen to "abide by this ruling and resign".

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. — Mohamed Nasheed (@MohamedNasheed) February 1, 2018

Others freed by the Supreme Court include a former vice president, a former defence minister, the leaders of two minor opposition parties, a ruling party lawmaker, a judge, a former chief prosecutor and a prominent businessman.

The court said the nine were to be immediately freed and afforded a fair re-trial.

Soon after the verdict was published online, hundreds of people gathered at the MDP headquarters to celebrate. They called for Yameen's resignation as well as a free and fair vote during a presidential election due later this year.

Hours later, police fired tear gas to disperse the crowd and arrested several people.

Police chief dismissed

The crackdown came after Yameen fired Commissioner of Police Ahmed Areef after he said the police would comply with the landmark ruling.

Attorney General Mohamed Anil announced Areef's dismissal at a press conference in Male, telling reporters the president had been unable to contact his police chief following the Supreme Court decision.

Anil said the government has not "received official or unofficial word on this ruling" and was "trying to verify its authenticity with the Supreme Court".

Speaking alongside the attorney general, Adam Shareef, the defence minister, called for calm and restraint, urging the public "to prioritise safety and security at this dangerous time".

The government respects the Supreme Court's rulings, he added.

In a post on Twitter, Ahmed Nihan, the majority leader, said ruling party lawmakers remain with "President Yameen's legitimate government, and are ready to defend the people’s rule".

Corruption confessions

Yameen has brushed off several attempts to undermine his rule in the past, despite a record in office marred by allegations of authoritarianism and corruption.

In 2016, an Al Jazeera investigation revealed how Yameen and his former deputy Ahmed Adeeb coordinated the theft of millions of dollars in tourism revenues.

The documentary, Stealing Paradise, also features secretly filmed confessions from three men who said they carried cash to the president in bags filled with up to $1m.

Yameen has denied the allegations and blamed Adeeb for the racket.

The then-vice president was arrested following a mysterious explosion on Yameen’s speedboat in 2015, and jailed on charges of corruption and plotting to kill the president.

Adeeb was among the nine whose release was ordered by the Supreme Court on Thursday.

The opposition said the decision of the top court, which has sided with Yameen in the past, "effectively ends Yameen's authoritarian rule".

Mariyam Shiuna, executive director of anti-corruption group Transparency Maldives, said the ruling "still entails a lot of political uncertainty".

There was, however, reason for hope, she said.

"The fact that political prisoners, many of whom are leaders of political parties and potential presidential candidates, are released means that the political environment may pave way for a more conducive environment for a competitive presidential election in 2018."