Ecuadorian President Rafael Correa was freed by soldiers from mutinying police late Thursday, Ecuadorian television reported.
He later appeared at the presidential palace in the capital Quito and addressed celebrating supporters.
Soldiers took Correa from a military clinic, where he had spent much of the day amid a mutiny by police over a new law changing their employment benefits.
Military forces loyal to Correas government reportedly moved against police who had allegedly blocked Correa from leaving the medical facility, where he had sought treatment for a possible leg injury and tear gas exposure after a scuffle with police whom he had confronted earlier Thursday.
Ecuador was under a state of emergency amid the mutiny, which Correa described as an attempted coup.
The emergency was declared after most police and some rank-and-file military troops refused to obey orders in a large part of Ecuador and took control of the largest police barracks in the capital and the airport, among other key facilities.
The mutiny spread quickly to the rest of Ecuador.
The security forces were protesting a law passed Tuesday by the National Assembly, which according to officers eliminates special awards, bonuses and other benefits. The government insists that these benefits were not being scrapped but allocated as salary.
Correa had personally confronted the first group of mutineers early Thursday. A scuffle erupted in a tight crowd of people, and Correa may have hurt his leg, while also suffering exposure to tear gas.
He was taken for treatment to Quitos Police Hospital, where he addressed Ecuadorian television, saying, "This is a coup attempt by the opposition and some police officers".
In a later telephone interview from the hospital, he said that he was being prevented from leaving the hospital by mutinous police.