At least 130 people, most of them children, were killed when Taliban gunmen stormed a school in the Pakistani city of Peshawar. (Reuters)

PAKISTAN’S ARMY chief warned his senior commanders just last Friday to be on guard for a major attack by Taliban extremists, and for good reason: In the past six months the army has conducted an aggressive campaign against militants based in the country’s northwestern tribal territories. The stepped-up vigilance, however, failed to prevent the disaster that befell the country Tuesday, when nine Taliban attackers rushed a school in the city of Peshawar and wantonly slaughtered at least 132 children and nine staff members.

It was, as President Obama said in a statement, a “heinous” act that underscored the “depravity” of the Taliban, who deliberately targeted children in the first through 10th grades at a military-sponsored institution. No hostages were taken: The attackers’ sole aim was to murder as many youngsters as possible. It was the bloodiest terrorist attack in Pakistan since 2007, one that was meant to derail modest but real progress by the army and government in fighting extremism.

To their credit, Pakistan’s prime minister and army chief quickly vowed to stay on course. “Our resolve to tackle this menace has gotten a new lease on life,” said Gen. Raheel Sharif, the commander who has overseen the groundbreaking offensive in North Waziristan and neighboring territories since June. Prime Minister Nawaz Sharif, who took office 18 months ago expressing support for negotiations with the Taliban, said, “We will take revenge for each and every drop of our children’s blood.”

The relative good news on a terrible day was that the attack was a reflection of the Taliban’s declining fortunes in Pakistan — not its ascendancy. Gen. Sharif, who won considerable praise from the Obama administration and Congress during a visit to Washington last month, has shown more willingness than his predecessors to squarely confront Islamic extremist groups that Islamabad has sometimes coddled or used as proxies. The Haqqani group, an Afghan Taliban faction, has been targeted for the first time, and a top U.S. commander in Afghanistan recently said it had been “fractured.” This month the Pakistan army killed a senior al-Qaeda operative who had been accused of plotting an attack on the New York subway.

Improving U.S.-Pakistani relations has been complemented by incipient detente between Prime Minister Sharif’s government and new Afghan President Ashraf Ghani. For years the Taliban has thrived in the fissures among the three governments; now, at last, there is a prospect for cooperation that could put more pressure on the extremists.

Tuesday’s horrific attack should prompt Pakistan’s leaders to take steps that are still needed to effectively defend the country. Prime Minister Sharif and his army commander must cooperate more closely; the prime minister should beef up a new counterterrorism authority and draw the military into it. Gen. Sharif should deliver on his words in Washington by acting against all extremist groups, including those that have conducted terrorist attacks against India.

The slaughtered children in Peshawar underline a truth that Pakistan’s elite have been slow to fully accept: Islamic jihadism poses a mortal threat to the nation. The best response to the atrocity would be for the army and government to join in an uncompromising campaign against the terrorists.