The Court ordered the immediate release and retrial of the exiled former president Mohamed Nasheed and other opposition leaders.

It declared that their original trials violated constitutional and international law.

The court decision effectively restores the opposition majority in parliament, reinstating 12 members who had been stripped of their seats.

Shortly after the ruling the police announced on Twitter that they were satisfied with the legality of the ruling and would enforce it.

However, the police commissioner Ahmed Areef was then dismissed by Attorney General Mohamed Anil at a hastily convened late-night press conference.

Attorney General Anil said Ahmed Areef had been sacked because he was uncontactable following the court order. Local media reported that he also said the president was “disheartened” by the police commissioner’s decision to enforce the ruling.

The attorney general said the government was reviewing the court order.

The country has seen political unrest since Mr Nasheed, its first democratically elected leader, was convicted in 2015.

His conviction and 13-year sentence was internationally condemned, and he was given political asylum in the UK. However, he is currently in Sri Lanka.

Former Vice-President Ahmed Adheeb Abdul Ghafoor and other opposition leaders were among the others named in the latest order.

It called for their immediate release and said the “questionable and politically motivated nature of the trials of the political leaders warrant a re-trial”.

In a tweet, Mr Nasheed called for President Abdulla Yameen to resign. The call was echoed in a joint statement issued by the country’s opposition parties.

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.

Mr Nasheed told local television that he planned to return to Malé, but not immediately.

“I will move forward wisely with the advice of the party and the united parties,” he said.

The US ambassador to the Maldives urged the country’s leader to respect the court’s judgement.

The Indian Ocean nation has been independent from Britain for 53 years, during which time it was ruled for decades autocratically by then President Maumoon Abdul Gayhoom.

It became a multi-party democracy in 2008, but since President Yameen took power in 2013 it has faced questions over freedom of speech, the detention of opponents and the independence of the judiciary.

The nation is made up of 26 coral atolls and 1,192 individual islands, and is popular among foreigners as a luxury tourist destination.