President Rafael Correa reasserted control over Ecuador on Friday and his disgraced police chief resigned after officers' protests at spending cuts rattled the left-wing leader, who accused foes of a coup attempt.
Police commander Freddy Martinez took responsibility for a revolt by his officers on Thursday, when Correa was physically attacked and trapped in a hospital for several hours before troops rescued him in a blaze of gunfire.
Eight people died in unrest across the country.
"A commander shown such lack of respect by his subordinates cannot stay in charge," Martinez said.
Television station Ecuavisa said three senior police officers were detained.
Police officers began to return to work on Friday, a new police chief was named and three days of mourning was declared.
The army increased security in streets around the presidential palace and soldiers helped guard banks to prevent looting.
Three presidents were ousted by popular protests in the decade before Correa took office in 2007, and for a few hours on Thursday it appeared he might be next.
More instability in the oil exporter could dent investor confidence already knocked by Correa's tough stance with the private sector.
"This was coordinated to create chaos, civil war, killings, to destabilize the government. They have not succeeded," Correa told visiting foreign ministers from across the region in a meeting broadcast on state TV.
"Personally, I am devastated and the nation is in mourning."
The fiery 47-year-old leader had expressed contempt for the rebel police officers' complaints over proposed cuts to bonuses when he addressed supporters after his rescue by troops.
State media said Correa's vehicle was hit by bullets as soldiers took him out of the hospital on Thursday night.
"They wanted to kill President Correa," the Andes state news agency said, adding that the bullet-proof vehicle was hit four times.
Dramatic TV footage showed an elite policeman guarding Correa being fatally shot as he held onto the vehicle and then slumping onto the tarmac.
Correa's relationship with the armed forces has been mixed, and Thursday's unrest could force a delicate line handling the military, which has helped topple governments in the past.
Some rank-and-file soldiers joined the protest, shutting the main airport, but the military top brass stood by Correa.
Correa is expected to purge rebel officers from police ranks and he could also choose to dissolve Congress and rule by decree, or call elections to try and solidify his power, although he might prefer to let things cool down first.
Correa, a close friend of Venezuela's socialist President Hugo Chavez, is part of the bloc of Latin American leaders fiercely critical of US policy, and he alienated investors when his government defaulted on $3.2 billion in global bonds.
Support at home and abroad
Correa remains popular at home and won support across the region on Thursday, from the White House to Havana.
Top South American diplomats arrived in Quito on Friday.
Even critics said it was important for Latin America and the United States to stand behind democratically-elected leaders.
Ecuadoreans were relieved the crisis did not spill into wider bloodshed, and many called for Correa to seek dialogue.
"Ecuador's image is ruined. It's tragic," said Eduardo Villavicencio, 60, who works at a foreign gold mining firm.
"They share the blame. There is no dialogue or understanding."
It was still not clear whether Correa was targeted in an organized coup attempt, as he and his supporters claim, or whether it was simply a protest that spiraled out of control.
The police were angered by plans to cut bonuses and freeze promotions as part of nationwide austerity measures that Correa is trying to push through in the face of a financial squeeze.
The US-trained economist, limping after knee surgery he underwent last week, was jostled while confronting protesters on the street early on Thursday.
Amid chaotic scenes, a tear gas canister was hurled at him and exploded near his face.
The government said eight people died, including two police officers killed in a 40-minute shootout as troops stormed the hospital where Correa took refuge.
Five civilians were killed in the city of Guayaquil, and 274 other people were hurt in the unrest, most of them in Quito.
Thousands of Ecuadoreans poured onto the streets to support Correa and, unlike during previous coups in OPEC's smallest member, there was no alternative leader waiting to take over.
It was, however, the toughest challenge yet to Correa, whose popularity has been stable at about 50 per cent despite Ecuador's slow recovery from the global economic crisis.
His social initiatives -- including health and education programs, a $35 per month stipend for the poor and home-care programs for the handicapped -- have helped give him the strong base of support that eluded his predecessors.
Late on Thursday, an emotional and combative Correa vowed to push ahead with his "citizens' revolution," which hinges on the state taking more control over the crucial oil sector.
Ecuador, which holds OPEC's rotating presidency, produces an average of 485,000 barrels of crude per day, and sends just under half of that to the United States.
It is seeking better terms from companies, including Italy's ENI, Brazil's Petrobras and Spain's Repsol-YPF.
Correa's survival and support -- plus the absence of a united opposition -- could strengthen his political hand in some ways, but analysts see troubled times ahead.
He still faces a showdown with Congress, where some members of his Country Alliance party reject spending cuts.
Ecuador's two-year-old constitution lets the president declare an impasse, dissolve Congress and rule by decree until a new presidential and parliamentary election.
Christian Voelkel, a London-based analyst at IHS Global Insight, said the international backing Correa received would give him a boost over the short term.
"But over the long term the incident will accelerate the deterioration of the economic and political environment," Voelkel said.
"Ecuador is heading for tumultuous times."