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

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

Gunmen then opened fire with rocket-propelled grenades and machine-guns, police chief Sohail Khalid said. About 70 attackers were in police uniform.

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

The town’s prison houses hundreds of Taliban and militants from banned groups.

Twelve people – including six police officers – were killed in the gun battle that raged for three or four hours after militants launched their assault.

The town’s civil commissioner Mushtaq Jadoon said that 30 hardened militants jailed for their involvement in major attacks or suicide bombings were among those who escaped.

The audacious attack began when militants blasted the main wall of the jail.

Those released jail include two local Taliban commanders, Abdul Hakim and Haji Ilyas, reports BBC Urdu’s Ahmed Wali.

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.

Attackers used loudhailers to call the names of particular inmates, Mr Jadoon said.

Fourteen fugitives were later re-arrested by police, he 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.

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”.

Mr Jadoon told a local TV station that 14 explosive devices planted in the jail had so far been defused.

Attack ‘threats’

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 has claimed responsibility for the attack. He said around 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.

The building is about a century old and officials say it was not constructed to house high-security prisoners.

Hundreds of inmates were freed in an assault on a prison in Bannu in northern Pakistan in April last year.

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

The attack appears to be part of a Taliban strategy to break jails instead of negotiating prisoner releases with government, the BBC’s Ilyas Khan reports from Islamabad.

Last month, police claimed they arrested some Taliban operatives who were planning to attack a jail in the southern port city of Karachi, our correspondent adds.

Monday night’s violence came hours before Pakistani politicians were to choose the country’s new president.

The replacement for Asif Ali Zardari is being elected by the members of both houses of parliament and the four provincial assemblies.