It was the biggest test to date of Rafael Correa's nearly 4-year-old presidency, a bloody trial by fire for a tenacious politician whose popular government had brought relative calm to a chronically unstable country.
The Ecuadorean leader called the police revolt, which left three dead, dozens injured and briefly paralyzed this Andean nation, a coup attempt. Not an outlandish claim for a country that had eight presidents in 10 years before Correa won office.
Correa's kindred leftist presidents, Hugo Chavez of Venezuela and Evo Morales of Bolivia, even accused the United States of pulling the strings behind the insurrection at an emergency meeting of South American leaders on Friday in Buenos Aires, Argentina.
But skeptical analysts said Thursday's tumult appeared instead to be a revolt that spiraled out of control by hundreds of modestly paid police officers protesting cuts in benefits.
"You can't dismiss the possibility that some opposition figures knew about it and supported it. But if it was a coup attempt, it was hugely amateurish," said Adam Isacson of the liberal Washington Office on Latin America think tank.
Analysts also tended to agree that Correa, a U.S.- and European-educated economist, emerged strengthened from the first violent challenge to his presidency in a traditionally volatile country of 14 million with a long history of short-lived governments and of meddling by Washington.
The armed forces high command stood by Correa, as did his most powerful political rival -- and governments in the region of every political stripe.
As life quickly returned to normal across Ecuador on Friday, Correa spoke by phone for 10 minutes with U.S. Secretary of State Hillary Rodham Clinton, who "encouraged an ongoing, rapid and peaceful restoration of order," said Clinton's spokesman, P.J. Crowley.
He said the two agreed "to continue to work together to strengthen Ecuadorean institutions and the rule of law."
Correa, 47, had ended Thursday triumphant, addressing supporters from the terrace of the presidential palace after his rescue in a hail of gunfire from the hospital where he'd been trapped for 10 hours by the insurrectionist cops.
Correa has a temper, and lost it in a tense standoff at a Quito police barracks with scores of jeering police rebels who were taking part in the blitzkrieg nationwide strike, in which several hundred troops also shut down Ecuador's two biggest airports.
"If you want to kill the president, here he is! Kill me if you want to! Kill me if you are brave, instead of hiding in the crowd like cowards!" Correa taunted the hostile crowd, loosening his slate-blue tie and thrusting out an unprotected chest.
Minutes later, rioting police penetrated his light security detail and roughed him up. Pelted by water and fainting from tear gas -- his right knee pounding from an operation last week -- Correa was lifted over a wall and onto the grounds of the hospital.
Merely showing up at the barracks, said Correa's former security minister Gustavo Larrea, "was like throwing gasoline on a fire. It elevated the tone of the conflict and, what's more, they took him hostage there. Because had he not gone, nothing would have happened."
Correa became trapped in the hospital, surrounded by hundreds of renegade cops who beat back with tear gas Correa loyalists trying to come to his aid.
"Correa's impulsiveness and penchant for direct confrontation were on full display," said Michael Shifter, president of the Inter-American Dialogue think tank.
As Correa recovered with an intravenous drip in his arm, he was visited by ministers, spoke by phone to presidents including Chavez and Colombia's Juan Manuel Santos, gave interviews to news media in which he said he was "practically captive" -- and received three delegations of aggrieved police officers. All while protected by presidential bodyguards.
His foreign minister, Ricardo Patino, claimed insurgents tried at one point to climb in by the roof. But the hospital's director, Cesar Carrion, said no armed police were ever allowed into the building.
Correa said he'd leave only "as president or as a corpse. But I'm not going to lose my dignity."
Whether Correa's life was at ever at serious risk was doubted by some analysts -- though there's no question that people were shooting at each other with automatic weapons during the roughly hourlong rescue operation.
"Correa never lost control of the government and there is no evidence anyone was plotting and seeking to oust and replace him," said Shifter.
Larrea agreed, discounting accusations by Patino and Correa that the rioters had been incited by supporters of former President Lucio Gutierrez, who co-led a 2000 coup.
Gutierrez vehemently denied any involvement, though he has been a strident critic of Correa. At the same time, Correa's most powerful rival, Guayaquil Mayor Jaime Nebot, publicly backed the government. So did the armed forces chief, Gen. Ernesto Gonzalez.
By dawn Friday, national police chief Gen. Freddy Martinez had resigned in shame, lamenting having been "disrespected" and "mistreated" by his subordinates.
It should be no surprise that some security force members are alienated by Correa.
He purged the military intelligence chief and other top officers in 2008, accusing them of withholding from him information they shared with U.S. agents. He also fired a top police commander he accused of exhibiting greater loyalty to Washington than Quito.
But in a country with Ecuador's history, a president needs to be careful how he treats the public servants who bear arms.
The civil service law passed Wednesday by a Congress dominated by Correa allies would end the practice of giving soldiers and police medals and cash bonuses with each promotion -- and extend promotion intervals.
That stings for police and soldiers, who earn well under $1,000 a month.
One police office said in an Ecuadorean TV interview, his face covered, that the new law would rob him of a 15-year bonus of $3,000 that he was due. Said another: "our salaries are lousy. We work without schedules, without overtime and on holidays."
The law has yet to take effect.
Gonzalez asked Correa to review and consider rewriting it.
So far, neither the president nor anyone in his government has responded.
Associated Press writer Frank Bajak contributed from Bogota, Colombia