COLOMBO - The Supreme Court of the Maldives ordered the release of all top political prisoners Thursday and lifted exiled former president Mohamed Nasheed's terrorism conviction.

The surprise ruling clears the way for Nasheed to return to his homeland and run for reelection against President Abdulla Yameen.

The atoll nation's 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.

Nasheed, who is living in self-imposed exile, was sentenced to 13 years in jail on a terrorism charge widely criticised as politically motivated.

In its order, seen by AFP, the country's top court said the "questionable and politically motivated nature of the trials of the political leaders warrant a re-trial". The court ordered authorities to "immediately free the jailed leaders until a court of law sentences otherwise".

It was not immediately clear what prompted the action by the court. Earlier this week opposition figures jointly petitioned the Supreme Court to remove Yameen and order an investigation into corruption allegations against him. Opposition figures including Nasheed and another five dissidents named in Thursday's order have united against Yameen.

They accuse him of "unprecedented corruption, including unjust enrichment from appropriation of state properties and funds for personal benefit, for the benefit of his family and political associates", according to the main opposition.

Among those who petitioned the top court was Yameen's half-brother and former president Maumoon Abdul Gayoom, whose legislator son 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 at 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 leave 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 by the end of this year.

A UN panel has ruled that his imprisonment was illegal and ordered the regime to pay him compensation.

The United States has said democracy is under threat in the strategically located archipelago, which sits on key international shipping lanes.