Image copyright AFP/getty Image caption Mr Nasheed was sentenced for terror offences in 2015

Former Maldives President Mohamed Nasheed has told the BBC he will return from exile to contest elections.

His decision comes a day after the Supreme Court cleared him of terrorism charges and said his trial in 2015 was "politically motivated".

The court also ordered the immediate release of other opposition leaders, sparking demonstrations as crowds of supporters celebrated the ruling.

Mr Nasheed said the country should prepare for "free and fair" elections.

"We are moving towards elections. I can contest and will contest," he told the BBC.

"We must set up proper procedures for inclusive, free and fair elections with full international observation."

Mr Nasheed also urged President Abdulla Yameen to honour the Supreme Court's landmark decision.

"President Yameen must abide by the Supreme Court ruling and release the political leaders immediately. [He] must also release other democracy activists in jail," he said.

Mr Nasheed, who is currently in Sri Lanka, was the island's first democratically elected leader.

The country has seen political unrest since he was convicted in 2015. His conviction and 13-year sentence was internationally condemned, and he was given political asylum in the UK.

Analysis: 'Tumultuous politics'

by Olivia Lang, BBC News

Thursday's verdict is a huge gain for the Maldivian opposition, which has been vying to oust the president for years.

It hasn't seemed like a battle they would win. Abdulla Yameen has kept a firm grip on power, overseeing the arrest of political opponents and restricting political protest and press freedom.

There is little left of the democracy that the Maldives became in 2008.

Every time the opposition tried to play a hand, Mr Yameen stopped them in their tracks. Last July, when the opposition had enough MPs to impeach the speaker of the parliament - an ally of Mr Yameen - troops were deployed to prevent them entering the building.

So is this the beginning of the end for Mr Yameen, as the opposition claim? If elections later this year are free and fair then Mr Nasheed would have a good chance of returning to office.

But that is still some time away. And in the tumultuous world of Maldivian politics, things can change very quickly.

Shortly after Thursday's ruling the police announced on Twitter that it 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.

The attorney general said Mr 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.

But the president's office later said it accepted the ruling and would comply with it.

Image copyright AFP Image caption Supporters gathered to celebrate the Supreme Court ruling

Former Vice-President Ahmed Adheeb Abdul Ghafoor and other opposition leaders were among the others named in the Supreme Court's 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".

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.