Justice Abdulla Mohamed, arrested by the army amid an outcry last month, was released soon after Mr Hassan took power.

Mr Nasheed's Maldives Democratic Party (MDP) said the president's resignation had been engineered by "rogue elements" of the police and military, along with supporters of former President Maumoon Abdul Gayoom.

"The opposition, supported by the army and police, offered an ultimatum to President Nasheed: step down or be faced with a bloodbath in the capital," the MDP said in a statement.

"President Nasheed thus resigned in order to protect the public from further violence. His resignation was involuntary in that he had no choice."

The MDP said a number of its members and government officials had been injured in overnight unrest, and said it feared for the safety of Mr Nasheed and senior members of his government.

Image copyrightbbc

Mr Nasheed's brother Ibrahim told the BBC the former president was now at home, but confirmed he had earlier been held for some hours against his will by security forces who said they were keeping him in the presidential palace for his own safety.

Mr Hassan - the former vice-president - described Mr Nasheed's resignation as a "generous decision... because he has taken into consideration the call from the people and he has also helped to prevent bloodshed".

"Elections will be in 2013 and, God willing, I will try to form a government of national unity and work with all political parties so that we can bring calm and quiet to the streets of Male and also to ensure that the rule of law is upheld," he told the BBC.

'No iron fist'

Mohamed Nasheed announced his resignation during a televised news conference.

"It will be better for the country in the current situation if I resign. I don't want to run the country with an iron fist. I am resigning," he said.

Analysis

By Olivia LangBBC News

It is a startling turn of events for a man heralded as the harbinger of change who pledged to complete the archipelago's transition to democracy.

In recent years, Mr Nasheed had attracted worldwide attention for his campaign for action on climate change, even holding an underwater cabinet meeting to highlight his cause.

But domestically, he appeared to lose his footing as a series of crises shook his government.

His resignation came within hours of a mutiny in police ranks which saw a few dozen officers side with protesters and then clash with soldiers in the streets.

The mutinying officers took control of the state broadcaster in the capital, Male, and began playing out messages in support of Mr Gayoom.

Reports that the army fired rubber bullets at the protesting police officers were denied by the president's office.

Sarah Harvey, a Briton who works in Male, told the BBC: "Last night was really noisy - there were protesters on foot and on scooters storming down the streets and chanting until the early hours of the morning.

"[Today] there's a curfew in the streets, but a few people are out and about," she added.

"I've heard that MDP activists were encouraging people to come out on the streets tonight to protest against the attempted coup."

Since then, correspondents say, the country has been gripped by constitutional gridlock - parties opposed to the president have dominated parliament since general elections the following year.

A one-time political prisoner, Mr Nasheed became a vocal figure in office on issues relating to the environment and climate change.

But he has faced constant opposition - from those loyal to former President Gayoom and from religious conservatives who accuse him of being anti-Islamic, says the BBC's South Asia analyst Jill McGivering.

That pressure has intensified with the prospect of next year's presidential elections. Opposition parties are jockeying for power as they try to extend their influence.

The wider question is how this crisis will affect the forthcoming elections - and what it says about the transition in the Maldives to mature democracy, our correspondent says.

The British Foreign Office is advising against "all but essential travel" to the capital Male, where a third of the population live, but says it has received no reports of unrest affecting the airport or tourist areas.

Are you in the Maldives? Have you been affected by the unrest? Send us your comments using the form below.

If you are happy to be contacted by a BBC journalist please leave a telephone number that we can
contact you on. In some cases a selection of your comments will be published, displaying your name as
you provide it and location, unless you state otherwise. Your contact details will never be published.
When sending us pictures, video or eyewitness accounts at no time should you endanger yourself or others,
take any unnecessary risks or infringe any laws. Please ensure you have read the terms and conditions.