The two policemen who were guarding the suspect at the hospital in La Linea de la Concepcion did not use their guns "to prevent the situation from turning into a drama", the town hall of La Lina said in a statement.
The suspect was taken to the hospital for treatment on Tuesday after he was injured during a police chase. But shortly after he arrived at the hospital about 20 people stormed the building, grabbed him and fled in several cars, the statement added.
VÍDEO | Este es el narco al que un grupo de encapuchados ayudó a liberar en las urgencias del hospital de La Línea https://t.co/cWoztqf1wd— laSexta Noticias (@sextaNoticias) February 7, 2018
La Linea mayor Juan Franco regularly complains of rampant drug trafficking in the city of around 65,000 people which is on the border with Gibraltar, the disputed British territory in Spain's southern tip.
"The enemy is very strong and we will have to think about the adoption of more measures" to fight drug traffickers, he told a news conference on Wednesday.
During an interview with AFP last year he said there was a feeling of "total impunity" in the city as drug traffickers operate almost openly and do not hesitate to challenge police, who complain they are under-equipped.
Spain's proximity to Morocco, a key source of cannabis, and its close ties with former colonies in Latin America, a major cocaine producing region, have made it an important gateway for international drug dealers.