ISLAMABAD, Pakistan — Pakistan’s military stormed a security outpost on Tuesday after Pakistani Taliban militants seized hostages there in an attempt to break out of detention, officials said.
Maj. Gen. Ahmed Sharif Chaudhry, the spokesman of the Pakistan military, said that 25 militants were killed in a fierce gun battle, and that seven surrendered to the security forces. Two soldiers were killed during the fire exchange and 10 others, including two officers, were injured, he said.
The fighting, in the northwestern province of Khyber-Pakhtunkhwa near the border with Afghanistan, was the latest outbreak of violence involving the Pakistani Taliban after a fragile peace deal between the militants and the government broke down last month.
A resurgence by the militants has strained relations between Pakistan and the Afghan government, which the Pakistani government accuses of sheltering the Pakistani Taliban.
The hostage crisis began on Sunday at a detention center in a military district in the city of Bannu. Thirty-five Taliban militants were under custody for interrogation at a detention center of the provincial counterterrorism force, officials said.
General Chaudhry said that one of the militants detained there had overpowered a security guard, seized his weapon and freed the other 34 militants. They took possession of weapons stocked at the compound and killed two officials of the counterterrorism force, while one security official was taken hostage.
Earlier, it was reported that the militants had taken several hostages, but on Tuesday the military said that there had been just one hostage. Khawaja Muhammad Asif, Pakistan’s defense minister, had also said on Tuesday that all hostages were freed after the military operation, although he did not specify the number of hostages.
Officials said that the security forces cordoned off the compound Sunday soon after the breakout attempt had begun and that two militants were killed in an initial exchange of gunfire while three others managed to escape.
Negotiations for an unconditional surrender broke down, leading to the commando raid on Tuesday, General Chaudhry said.
“The terrorists wanted a safe passage to Afghanistan,” he said. “This condition was totally rejected, and the terrorists were told that it was out of the question.”
The Pakistani Taliban, known as Tehreek-e-Taliban Pakistan, or T.T.P., have staged more attacks in recent months after the breakdown of a peace process with the government.
A Pakistani soldier and two civilians were reportedly killed in an attack on Monday by the militants in Miran Shah, in the region of North Waziristan along the border with Afghanistan. In Peshawar, the capital of Khyber-Pakhtunkhwa Province, an officer of a civilian intelligence agency was shot dead in an attack on Monday that was claimed by the T.T.P.
In separate attacks in Khyber-Pakhtunkhwa last week, at least one civilian and five soldiers or police officers were killed by T.T.P.-affiliated militants.
Businessmen in Peshawar have said that they have started receiving extortion threats from the militants, and called on officials to improve security in the region.
Pakistan’s military began a massive operation against the Pakistani Taliban in 2014 when peace talks broke down, after years of violence and disruption that threated much of the country. The offensive sent the militants scattering, leading to a lull in attacks within Pakistan for years.
But more recently, the T.T.P. — which is actually a conglomeration of militant cells that have joined brands — has again begun to pose a threat to the security forces and the government.
Pakistani officials say that the Afghan Taliban’s takeover of Afghanistan last year after decades of insurgency has been a boost for the T.T.P., which is a separate group but has a sympathetic ideology and origins in the religious schools in Pakistan’s tribal areas. The Afghan government has denied supporting the T.T.P.
Political tensions in Pakistan, already at a breaking point after Imran Khan was forced out as prime minister in April, has only deepened as militant violence has increased.
The government of Prime Minister Shehbaz Sharif has accused Mr. Khan, whose political party has been in charge in Khyber-Pakhtunkhwa for nine years, of turning a blind eye to a resurgent militant threat there during his years in power.
Mr. Khan, however, has kept up a pressure campaign against Mr. Sharif’s government, accusing it of allowing law and order to deteriorate since taking office.
Some analysts said that the recent peace negotiations between the government and the T.T.P., which began while Mr. Khan was prime minister, gave the militants an opportunity to regroup.
Abdul Basit, a research fellow at the S. Rajaratnam School of International Studies, Singapore, who tracks militancy in Pakistan, said that conditions both within Pakistan and within neighboring Afghanistan have contributed to the resurgence.
“The Taliban’s return to power and the sanctuaries in Afghanistan have had a rejuvenating impact on the T.T.P.,” Mr. Basit said.
He said that small arms and other weaponry that had been provided to the Afghan government by the United States and NATO forces for years made their way into the T.T.P.’s hands.
“The possession of these weapons has increased the accuracy and lethality of T.T.P.’s attacks as well,” Mr. Basit said.