Male:  The first democratically elected President of the Maldives resigned on Tuesday and was replaced by his Vice President after the police and army clashed in the streets of the island nation amid protests over the arrest of a top judge.

Mohammed Waheed Hassan, who previously worked as a top UNICEF official, was sworn in as the new Maldivian President in the afternoon. Soon after, the judge was released.

The resignation of President Mohamed Nasheed marked a stunning fall for the former human rights campaigner who defeated the nation's longtime ruler in the country's first multiparty election.

Nasheed was also an environmental celebrity, traveling the world to persuade governments to combat the climate change that could raise sea levels and inundate his archipelago nation.

Nasheed presented his resignation in a nationally televised address this afternoon after police joined the protesters and then clashed with soldiers in the streets. Some of the soldiers then defected to the police side.

"I don't want to hurt any Maldivian. I feel my staying on in power will only increase the problems, and it will hurt our citizens," Nasheed said. "So the best option available to me is to step down."

Maldivians waving flags poured into the streets to celebrate Nasheed's resignation. Some playfully threw water at each other.

Hassan, who was educated at Stanford University in California, was the first television anchor in Maldives history and the first person shown live when local TV went on the air in 1978, according to his official biography.

He became a top education official in the country, but eventually left under duress after getting elected to the Parliament and incurring the ire of the autocratic government ruling in the 1990s, his biography said.

He joined UNICEF and rose to be its representative in Afghanistan, helping rebuild schools and provide health services after the fall of the Taliban.

Hassan's office denied widespread reports that military pressured Nasheed to resign in the wake of the clashes.

"It was not a coup at all, it was the wish of the people," said Ahmed Thoufeeg, Hassan's secretary.

An advisor for Nasheed, who spoke on condition of anonymity because of sensitivity of the situation, also dismissed claims the resignation came under duress from the military.

The adviser said Nasheed was left with two choices: order a bloody military crackdown on police dissidents or resign.

The latest protests in this Indian Ocean nation known for its lavish beach resorts erupted after Nasheed ordered the military to arrest Abdulla Mohamed, the chief judge of the

Criminal Court. The judge had ordered the release of a government critic he said had been illegally detained.

Hassan -- then the Vice President, the Supreme Court, Human Rights Commission, Judicial Services Commission and the office of the United Nations High Commissioner for Human Rights all called for Mohamed to be released.

Nasheed's government accused the judge of political bias and corruption, said the country's judicial system had failed and called for UN help to solve the crisis.

The crisis came to a head on Tuesday when hundreds of police demonstrated in the capital, Male, after officials ordered them to withdraw protection for government and opposition supporters protesting close to each other. The withdrawal resulted in a clash that injured at least three people.

Later, troops fired rubber bullets and clashed with police.

When Nasheed visited the police and urged them to end the protest, they refused and instead chanted for his resignation.

Mohamed was released after Hassan took power.