JOLO, Philippines (AP) — At least 29 detainees escaped from a jail in the southern Philippines on Saturday when a guard briefly left his post, but 17 of them were immediately captured when law enforcers fired warning shots, police said.

The 12 detainees who managed to escape successfully from the police jail in Jolo town were mostly facing drug charges and were being hunted by police, troops and village guards in nearby towns, police said.

The jailbreak was staged when a police guard left to take a break, but other policemen sprang to action and arrested 17 of the escapees in a melee just outside the jail, located in the Jolo townhall compound in the heart of the port town.

Officials removed several policemen from their posts following the jailbreak, which was being investigated, police said.

Abu Sayyaf extremists are active on Jolo Island in predominantly Muslim Sulu province, about 950 kilometers (590 miles) south of Manila, but those captured are detained in a better-secured jail in southern Zamboanga city or elsewhere.

Many jailbreaks occur in the Philippines each year due to lax security and poor prison conditions.