Dirty Face is in intensive care at the hospital, where he is recovering from his gunshot wounds.
The armed gang members had held five hospital workers hostage for more than an hour, an employee told local newspaper El Diario.
Activists circulated a video clip on social media in which masked men wielding guns pushed a woman screaming through one of the hospital gates and forced her back into the building.
Other staff at the hospital, located in Chune, western Ecuador, said they locked themselves in hospital rooms as gunmen stormed the rooms in search of the teen.
A hospital official told El Diario newspaper that the gunmen “apparently didn’t know the distribution of the hospital rooms, so these petty criminals were combing all the rooms in the building.”
He added: “Thank God and the police we are still alive to tell what happened.”
Ecuador’s President Guillermo Lasso praised the police, saying their intervention had saved many lives.
Ecuador’s president posted a video on Twitter of armed officers entering the hospital building before arresting the gang members.
In recent years, Ecuador has witnessed increased violence by armed gangs, some of whom resort to horrific practices such as beheadings. The country also witnessed a series of bloody prison riots.
Analysts attribute this increasing violence in Ecuador to Mexican gangs whose activities have spread to the country, where they recruit local gangs to smuggle cocaine.
Since taking office last year, Ecuador’s president has declared a state of emergency in the country several times in an attempt to curb the escalating violence.
Earlier this November, President Laso said attacks by the increasingly powerful drug cartels amounted to a declaration of war.