The militants killed six policemen, six Shiite Muslim prisoners and two civilians during Monday night's attack in the town of Dera Ismail Khan, said the town's commissioner, Mushtaq Jadoon. One of the Shiites was beheaded.

Fifteen policemen were wounded, said Jadoon.

Around 70 militants arrived at the prison by car and motorcycle at around 11:30 p.m. to begin the attack, which lasted for about four and a half hours until most of the fighters escaped, said intelligence officials, speaking on condition of anonymity because they were not authorized to talk to the media.

The attack began with a huge explosion that one resident, Sharafat Khan, said was so loud that "it rattled every house in the neighborhood."

The militants then detonated dozens of smaller bombs at different points along the prison walls, causing them to collapse, said Jadoon. They also fired rocket-propelled grenades and lobbed hand grenades during the attack, he said.

Security forces engaged the attackers, who were chanting "God is great" and "Long live the Taliban," intelligence officials said. At least eight attackers disguised in police uniforms entered the prison on motorcycles adorned with Taliban flags and used megaphones to call out the names of specific prisoners for whom they were looking.

The militants broke open the cells and freed 253 prisoners, including 25 "dangerous terrorists," said Jadoon.

Pakistani Taliban spokesman Shahidullah Shahid claimed responsibility for the attack, saying 150 militants took part and around 300 prisoners were freed. Eight of the attackers wore suicide vests, and two detonated their explosives, Shahid told The Associated Press by telephone from an undisclosed location.

Authorities captured nine prisoners who escaped and were searching for the others, as well as the militants, said Jadoon. Army soldiers were called in as reinforcements.

A curfew has been imposed in Dera Ismail Khan and the nearby town of Tank while the search goes on, said Amir Khattak, Dera Ismail Khan's deputy commissioner. The town is located near Pakistan's semiautonomous tribal region, the main sanctuary for Taliban and al-Qaida militants in the country.

Officials received a letter threatening an attack on the prison, but they didn't expect it so soon, said Khalid Abbas, head of the prison department in Khyber Pakhtunkhwa province.

In April 2012, Taliban militants armed with automatic weapons and rocket-propelled grenades battled their way into a prison in the city of Bannu in northwest Pakistan, freeing close to 400 prisoners, including at least 20 described by police as "very dangerous" insurgents.

One of the militants freed in that attack, Adnan Rasheed, recently gained attention by writing a letter to teenage education activist Malala Yousafzai, who was shot in the head by the Taliban last year in an attempt to kill her. Rasheed said he wished the attack hadn't happened, but told Malala that she was targeted for speaking ill of the Taliban.