Ecuadorean troops have stormed a hospital to rescue President Rafael Correa from renegade police officers who had blocked him inside the facility.

TV images showed heavy gunfire before Mr Correa was taken out of the building, in the capital city of Quito, to the country’s presidential palace.

Other footage showed one member of the security forces lying in the street, apparently wounded by the shooting.

Soldiers with shields then rushed over to help him, as a voice called out over a loudspeaker: “Don’t shoot. Don’t shoot.”

Two police officers reportedly died in the violent end to a stand-off that has shaken the South American nation.

The president, in a speech from the palace’s balcony told his supporters an attempted coup had been defeated.

Mr Correa said the police rebels had planned to kill him, adding that at least one officer had “fallen” during fighting around the hospital.

“Believe me that, when I was freed and they told me that there was at least one policeman fallen, I cried, not out of fear, but sadness,” he said.

Mr Correa had initially gone to the hospital after being shoved and tear-gassed by demonstrators.

The police, protesting against budget cuts, then surrounded the hospital.

But the troops managed to get the president safely out of the building, where he had spent most of the day.

Airports had been shut down and major roads blocked during the nationwide police strike.

The government declared a state of emergency, putting the military in charge of public order and suspending civil liberties.

The country’s police chief has resigned following the rebellion.

During the hospital siege, Mr Correa, 47, had insisted he would not negotiate with dissident officers unless they ended their demonstration.

“I leave here as president or they take me out as a corpse,” he said in a telephone interview from the hospital.

He also accused rivals of trying to topple him in a coup.

The protesters oppose a law that would cut their benefits, as part of austerity measures.

Witnesses said there was looting in Quito and in Guayaquil, and that many workers and schoolchildren had been sent home.

Britons in Ecuador are being advised by the Foreign Office to stay indoors and put travel plans on hold until the situation improves.

Ecuador, a South American OPEC member of some 14 million people, has a long history of political instability.

Street protests toppled three presidents during economic turmoil in the decade before Mr Correa took power.