The hostage takers, who were suspected of being members of various militant groups including the Tehreek-e-Taliban Pakistan (TTP), overpowered their jailers and snatched weapons on Sunday.
"All the hostages have been freed," Defence Minister Khawaja Muhammad Asif told parliament. "Ten to 15 men from the SSG (special forces) including an officer were wounded while two were martyred."
Elite troops stormed the police station around noon when differences broke out between the hostage takers over how to handle their captives, Asif said, with witnesses reporting blasts and heavy firing.
The suspected militants were being held on suspicion of terrorism and had demanded safe passage to Afghanistan in return for releasing the hostages, who included at least eight police officers and military intelligence officials.
"There were 33 terrorists from different groups who had been arrested and jailed in the counter-terrorism department compound," Asif said.
"One of them hit his guard on the head with a brick while going to the toilet and snatched his weapon," he added, explaining how the siege unfolded.
The TTP, which is separate from the Afghan Taliban but with a similar hardline Islamist ideology, emerged in Pakistan in 2007 and carried out a horrific wave of violence that was largely crushed after a military operation beginning in 2014.
Attacks are rising again since the Afghan Taliban seized control of Kabul last year, with most targeting security forces.
Racketeering has infested Pakistan's borderlands, locals say, with the TTP emboldened by its sister movement's success.
A shaky months-long ceasefire between the TTP and Islamabad ended last month.
About 300 incidents of militancy have been recorded in 2022 in Khyber Pakhtunkhwa province, which borders Afghanistan, according to the government.
The defence minister said at a press conference in Islamabad that a fresh security operation against militancy in the region must be carried out.
"There's a spillover effect from the situation in Afghanistan and that's affecting Pakistan, we have to launch this operation," he said.
The police station is within a cantonment area in Bannu, adjacent to Pakistan's formerly self-governed tribal areas and close to Afghanistan.
Offices and roads were closed and checkpoints were set up around the area.
Local schools were ordered shut on Tuesday out of fear of more kidnappings, a senior government official at the scene told AFP.
The same source earlier said Pakistani officials had asked the government in Kabul to help with the release of the hostages.
The TTP said its members were behind the incident and demanded authorities provide them safe passage to border areas.
A spokesman told AFP that special forces suffered heavy casualties in the clearance operation and had not been able to enter the police station.
Overnight on Monday, at least 50 Pakistan Taliban militants stormed another police station in Wana -- also close to the Afghan border and about 200 kilometres south of Bannu -- according to local government and senior police officials, both of whom asked not to be named.
The group locked up police officers and seized weapons before border force troops moved in to take back control.
The TTP claimed responsibility, saying two police officers were killed.
Authorities have not officially acknowledged the incident.