Media playback is unsupported on your device Media caption The militants used a loud hailer to call prisoners out by name, as Orla Guerin reports

Taliban militants have freed 248 prisoners in an assault on a prison in north-west Pakistan, officials say.

Militants armed with automatic weapons, rocket-propelled grenades, mortars and bombs blasted down the walls of the jail in the town of Dera Ismail Khan and streamed inside, reports said.

A gun battle lasting several hours went on into the early hours of Tuesday. At least 13 died, including six police.

Correspondents say it is a huge embarrassment for authorities.

The attack was similar to an assault on a prison in nearby Bannu in April last year, in which almost 400 prisoners were freed.

Analysis The Taliban assault comes on the day parliament is electing a new president. We will never know if the timing was deliberate, but it has hugely embarrassed the government, and once again highlighted the ability of the militants to strike at will. Suggestions the authorities had advance warning of the attack, but did not act on it, only make matters worse. No high-profile Taliban members were being held at the Dera prison, but at least 30 militants freed in the assault are described by the authorities as "hardened" Taliban fighters. The attack rekindles memories of a 2012 jailbreak in the nearby city of Bannu in which about 400 prisoners escaped, including Adnan Rashid, a radicalised former member of the military who recently wrote an open letter to child activist Malala Yousafzai explaining why she was attacked by the Taliban. The Dera jail attack comes a month after the police said they had arrested a group of militants who were planning to launch a similar attack on Karachi Central Jail. This is indicative of an emerging Taliban strategy to break jails instead of negotiating the release of their prisoners by taking hostages, which they have done in the past.

Reports also suggest intelligence had warned of an impending attempt on the jail two weeks ago.

This latest assault demonstrates the weakness of the Pakistani state, says the BBC's Shahzeb Jillani in Karachi.

The state appears not to have the capacity, and some would say the will, to rein in hardened militants, he says.

Police uniforms

The attack in the town of Dera Ismail Khan began with shooting and huge explosions at around midnight on Monday (15:00 GMT).

Up to 100 attackers, some wearing police uniforms, bombarded the prison with rockets and mortars before going inside.

The town's civil commissioner, Mushtaq Jadoon, said attackers used loudhailers to call the names of particular inmates.

An ensuing gun battle raged for three or four hours.

Katherine Houreld, a correspondent for Reuters news agency, told the BBC it had been a "very sophisticated attack - they blew the electricity line, they breached the walls and they set ambushes for reinforcements".

"When the shooting started, we immediately got into an armed police vehicle and parked on the road in front of the main gate," injured policeman Hidayat Ullah told AP news agency from his hospital bed.

"After this, we heard an explosion and the main gate exploded. After this, we started shooting towards the main gate from our armed vehicle.

"During this time, maybe either a rocket launcher or a mortar shell hit the vehicle. Two of our policemen were killed on the spot, and three of us were injured. We got down from the armed vehicle, and after that I don't know what happened."

The town's prison is a century old and is said not to have been designed for high-security inmates, but houses hundreds of Taliban fighters and militants from other banned groups.

Mr Jadoon said 30 "hardened militants", who had been jailed for their involvement in major attacks or suicide bombings, were among those freed.

He was also quoted as saying that militants had taken away six women, five of them inmates and the other a police officer.

An unnamed official told AFP news agency that jail records and an office had also been torched.

The town is in Khyber Pakhtunkhwa Province, next to Pakistan's mountainous tribal region.

Image caption The audacious attack began when militants blasted the main wall of the jail. Image caption Scenes from inside the jail showed quarters charred from the heavily armed militants' bombs and grenades. Image caption At least 12 people were killed, including six police officers, and others were injured. Image caption There had been intelligence predictions of the attack which is very similar to a jailbreak in the area last year. previous slide next slide

Among the inmates freed were two local Taliban commanders, Abdul Hakim and Haji Ilyas.

Also released is a sectarian militant, Waleed Akbar, the principle suspect in last year's attacks on Shia mourners in Dera Ismail Khan during the Shia mourning month of Moharram.

Fourteen fugitives were later re-arrested by police, Mr Jadoon said.

A curfew has now been imposed on Dera Ismail Khan as police hunt for the remaining escaped prisoners, but correspondents say this will be a difficult task as they flee into tribal areas.

Mr Jadoon told a local TV station that militants had booby-trapped the building with explosive devices, which had now been defused.

The chief minister of Khyber Pakhtunkhwa province, Pervez Khattak, branded the incident a failure of several agencies.

Attack 'threats'

Under attack Prime Minister Nawaz Sharif has faced brazen attack since he took office on 5 June: 27 July: 57 killed as bombs hit market in Parachinar , near Afghan border

57 killed as bombs hit market in , near Afghan border 24 July: Attackers storm office of ISI intelligence agency in Sukkur ,

Attackers storm office of ISI intelligence agency in , 10 July: Chief security officer of Pakistani President Asif Ali Zardari and aides killed in Karachi bomb attack

Chief security officer of Pakistani President Asif Ali Zardari and aides killed in bomb attack 30 June: At least 56 people killed in bomb attacks in Quetta and Peshawar

At least 56 people killed in bomb attacks in and 23 June : Gunmen kill 10, including at least nine foreign tourists, after storming hotel at Nanga Parbat mountain base camp

: Gunmen kill 10, including at least nine foreign tourists, after storming hotel at mountain base camp 15 June: Fourteen students killed in blast on bus at women's university in city of Quetta; hours later gunmen attack Quetta hospital, killing 10 Rising tide of extremist violence

A local resident told the agency that the initial blast was so loud that "it rattled every house in the neighbourhood".

The attackers were chanting "God is great" and "Long live the Taliban", officials said.

Pakistani Taliban spokesman Shahidullah Shahid said his group carried out the attack. He said about 300 prisoners had been freed.

The authorities are reported to have received intelligence about an impending attack two weeks ago, but prison officials said they did not expect it to come so soon.

A Taliban spokesman said one of their commanders freed in an assault on a prison in Bannu in northern Pakistan in April last year played a key role in the latest jailbreak.

Correspondents say the authorities will face questions about how militants were able to stage a virtually identical attack in Dera Ismail Khan.

Monday night's violence came hours before Pakistani politicians elected Mamnoon Hussain from the ruling PML-N party as the country's new president.