Pakistani Taliban militants carried out their deadliest attack on the country’s military in nearly a decade Friday, storming an air force compound and killing 29 people — many of whom had been praying in a mosque.

The attack, a gruesome reminder of the reach of Taliban fighters in Pakistan, unfolded shortly before dawn on the outskirts of Peshawar in northwestern Pakistan.

Maj. Gen. Asim Bajwa, an army spokesman, said 13 Pakistani Taliban militants disguised in paramilitary uniforms entered Camp Badaber from two locations. Security officials quickly engaged the militants, who were armed with rocket launchers and assault rifles, but at least one of the Taliban fighters managed to enter the mosque during morning prayers.

“People were busy preparing for that, and they were unarmed and vulnerable, but these terrorists and these animals attacked and killed them,” Bajwa said.

Twenty-three air force personnel and three civilians were killed. An army officer and two soldiers were also killed while battling the militants. Eventually, all 13 terrorists were shot and killed before they could penetrate “deep” into the compound, Bajwa said.

In a statement, the Pakistani Taliban asserted responsibility for the attack, saying it was in retaliation for the ongoing military operation in the country’s northwestern tribal belt. That operation intensified in December after the Pakistani Taliban stormed an army-run school in Peshawar and killed about 150 students and teachers.

Since then, Pakistani military officials say they have largely driven the group from its havens in North Waziristan by capturing or killing thousands of militants. But others, including Pakistani Taliban leader Maulana Fazlullah, are believed to have fled across the border into Afghanistan.

Bajwa said the army has “recordings” that trace Friday’s attack back to Afghanistan.

“This operation was planned in Afghanistan and executed from Afghanistan,” Bajwa said. “That doesn’t imply that the government or state of Afghanistan was involved in this . . . but it is also a fact that there are a number of areas which are not in the control of Afghan security forces.”

Such a distinction may be crucial to efforts by Western diplomats to resolve recent tensions between Pakistani and Afghan leaders over accusations that each country harbors terrorist groups that carry out attacks on the other.

Last month, Afghan President Ashraf Ghani angrily blamed Pakistan for a series of attacks in Kabul, noting that Afghan Taliban leaders have historically found refuge on Pakistani soil.

Both Pakistani Prime Minister Nawaz Sharif and the country’s army chief, Gen. Raheel Sharif, rushed to Peshawar on Friday afternoon to oversee the response to the attack. In a statement, U.S. Ambassador Richard G. Olson also condemned the “senseless and inhumane act” and said that “the United States stands with Pakistan in its struggle against terrorism.”

The assault was the deadliest in Pakistan since May, when 45 Shiite Muslims were massacred on a bus in the port city of Karachi.

Overall, however, Pakistani officials say there has been a 70 percent decline in major terrorist attacks this year, which they attribute to the ongoing military offensive.

But Friday’s attack shows that the Pakistani Taliban still has the capability to pull off headline-grabbing strikes, especially in the northwestern part of the country.

The air force compound was constructed in the late 1950s as a CIA surveillance base during the Cold War. After the CIA abandoned it in the 1970s, it became a housing compound for the Pakistani air force. The camp is about five miles from an airstrip where fighter jets and transport planes are kept.

Although many Pakistanis initially praised the military for repelling Friday’s assault, the mood in the country shifted by evening, when Bajwa announced that the death toll had risen dramatically. Now, the attack is renewing debate over the vulnerability of military facilities in this nuclear-armed country.

In September 2014, al-Qaeda militants sneaked onto a naval base in Karachi and launched an hours-long gun battle that killed a Pakistani sailor. Two years earlier, another security official was killed during an attack on an air base near the capital, Islamabad.

In 2011, Pakistani Taliban militants stormed Faisal air base in Karachi, killing 18 military personnel while also torching two U.S.-built surveillance planes. There was also a series of attacks near the army headquarters in Rawalpindi in 2009, including a suicide bombing in December of that year that killed several high-ranking military officers.

But Pakistani officials say Friday’s attack appears to have resulted in the largest loss of service members in a single terrorist strike since 2006, when about 40 Pakistani soldiers and army recruits were killed in a suicide bombing near Peshawar.

Still, Pakistani officials on Friday stressed that the country is winning its battle against the Pakistani Taliban.

“We are cutting the militants away from entering into the city, but there are many routes from where they can enter,” said Mushtaq Ghani, a spokesman for the Khyber Pakhtunkhwa provincial government. “We are at war, and such scattered attacks are possible.”

Haq Nawaz Khan in Peshawar and Shaiq Hussain in Islamabad contributed to this report.

Read more:

Today’s coverage from Post correspondents around the world