Pakistani security forces retook a counter-terrorism interrogation centre in the north-western town of Bannu on Tuesday, two days after it was seized by Islamist militants.
All hostages, some slightly wounded, had been rescued.
The special forces killed all the Pakistani Taliban militants who had earlier this week overpowered guards, seized arms and taken hostages, AP reported.
The forces were still looking to clear the compound.
Six security officials and several detainees were inside the centre, several sources told Reuters.
The “good news is we successfully recovered all the hostages from the terrorists”, one security official said. “Some of them are slightly injured but they are fine.
“The operation is being concluded and there is no more resistance … the security forces have entered the compound.”
Initial reports said nine security force personnel had been wounded.
Militants took over the compound on Sunday. Reuters reported that six security officials and several inmates were inside.
Security forces had surrounded the camp that houses an interrogation centre, Bannu, where about 20 fighters from Pakistan's branch of the Taliban, known as Tehreek-e-Taliban Pakistan (TTP), were holed up.
“All options failed and the terrorists refused to free innocent people, so we decided to use force,” another senior security official told Reuters. He added that an operation was not launched earlier to protect the safety of the hostages.
He said minimum force had been used to ensure the hostages' safe release.
Local residents said they heard explosions coming from the vicinity of the centre on Tuesday.
The military did not immediately respond to a request for comment, Reuters said.
Pakistani authorities on Monday had opened talks to try to resolve a stand-off with the militants.
The TTP, which has stepped up attacks since it announced the end of an Afghan Taliban-brokered ceasefire with the government last month, has long used violence in a bid to take over the country.
According to a provincial government spokesman, the militants were demanding safe passage to Afghanistan.