The attacks came the day politicians are due to choose a new president in a largely ceremonial vote, and two days before a major Shia festival which security officials have warned could be attacked.

Another security official said provincial authorities received warnings of the impending attack two weeks ago.

He said phone intercepts indicated the gunmen had been planning a jail break and interrogations of captured fighters confirmed it.

Security officials had alerted the provincial governor of the threat based on the intercepts.

The Pakistani Taliban said they had sent a squad of 100 fighters and seven suicide bombers on a mission to free some of their top leaders, and they said they released 250 prisoners.

Mushtaq Jadoon, the town's civil commissioner, said the 253 escaped prisoners included 30 top militants and six people on death row.

Those who escaped are believed to have been whisked away to the lawless tribal areas of South and North Waziristan.

The heavily guarded jail houses around 5,000 prisoners.

A senior Taliban official told Reuters separately the attack on the prison was masterminded by Adnan Rashid, a Taliban commander who was himself freed when his prison in the northern town of Bannu was overran by militants last year.

After that attack, militants told Reuters they had been helped by insiders in the security services.

An inquiry later found there were far fewer guards on duty than there should have been and those who were there lacked sufficient ammunition.