The Pakistani students killed and wounded in the Bacha Khan University attack were victims of the Pakistani military’s long collaboration with the Taliban. Photograph courtesy A. Majeed / AFP / Getty.

In Mary Shelley’s “Frankenstein,” the eponymous scientist, saddened by the death of his mother, sets out to create a human replicant in his laboratory. But instead of a human, a giant grotesque emerges, with yellow eyes, over-stretched skin, and a volatile disposition. Victor Frankenstein refers to it as “the Monster” and “the Creature.’’ His creation runs wild, killing Victor’s bride and his best friend, driving its creator to torment and sadness.

The tale of Frankenstein is the proper lens through which to view the attack by Taliban gunmen this week on a school in Pakistan. The assault, at Bacha Khan University in the city of Charsadda, killed at least twenty-two people and wounded at least nineteen. In this case, Victor Frankenstein, the scientist, resembles the generals of the Pakistani military, whose Creature is the out-of-control Pakistani Taliban.

The attack in Charsadda could have been worse: guards at the university killed a man before he could detonate an explosive vest that he’d wrapped around his body. Last year, there was an even more horrific assault on a school in the nearby city of Peshawar, where Taliban gunmen killed a hundred and forty-five people, most of them children.

In both cases, Pakistan’s leaders vowed to crush the Taliban. And the Pakistani military has launched a series of offensives in the desolate reaches of the Federally Administered Tribal Areas, where the group has its headquarters. We can only hope that the Pakistani military succeeds. But this is where our sympathy should end—and where the tale of Pakistan’s Frankenstein begins.

The Afghan Taliban came together with the assistance of the Pakistan military, which helped organize the group in the mid-nineties, during the long and horrible civil war that followed the withdrawal of the Soviet Union from Afghanistan. By 1995, with tens of thousands dead, Afghanistan had devolved into a state where rapacious warlords and their gangs fought each other over the spoils of conflict, which often included the country’s young women and boys. There was no functioning government.

Pakistan’s military-intelligence service, known by its acronym, the I.S.I., feared that the chaos would spread across the border. So, spotting a group of fierce fighters driven by a medieval vision of Islam, the I.S.I. poured its support behind them. The Taliban, led by a one-eyed cleric called Mullah Omar, swept across the country and captured the capital, in 1996. (The story has been told in many places, including in “The Wrong Enemy,” from 2014, by the Times reporter Carlotta Gall.) Omar gave sanctuary to another religiously inspired madman, Osama bin Laden, and they stayed in Afghanistan until they were chased away by American forces, in 2001.

Following the American invasion, the Taliban’s leadership (Omar included) fled to Pakistan, where it was received with open arms by the I.S.I. Over the next several years, as the Americans neglected their Afghan project, the Taliban grew stronger in their safe havens. All the while, the U.S. government lavished billions on the Pakistani government and military, even as they betrayed their benefactors. In Afghanistan today, the Taliban are as strong as they have been at any point since 2001.

While the Afghan Taliban flourished in its Pakistani sanctuaries, an unintended consequence developed: the ideology of the Taliban took root in Pakistan itself. Before long, the Pakistani Taliban was born, and it was as radical—and in some cases even more radical—than its Afghan progenitor. While the relationship between the various groups of the Pakistani and Afghan Taliban is complex, there is no question that the Pakistani movement is a spin-off of the Afghan one.

For years—indeed, even today—the Pakistani generals imagined they could have it both ways: that they could support the Afghan Taliban while ignoring the Taliban inside Pakistan. The Pakistani military often aided the C.I.A.’s drone campaign in Pakistan, but, while the Americans wanted to go after both groups of Taliban, the Pakistanis typically only helped them with the Pakistani cells. The Pakistani generals were playing a double game inside a double game: they took the Americans’ billions and supported the Taliban fighters who were killing the Americans, and they secretly helped the Americans kill Pakistani Taliban in the C.I.A.’S drone war, letting the Pakistani civilian leaders take the heat.

Not surprisingly, the double-double game was too clever by half. As the Afghan Taliban flourished, the Pakistani Taliban, occupying the same safe havens in the tribal areas, spun out of Pakistan’s control. By 2009, the Pakistani Taliban was so strong that they pulled within sight of Islamabad, the capital.

Since then, the Pakistani military has mounted a number of military operations against the Pakistani Taliban and has done some real damage. Last summer, the Pakistani Army launched a major military operation against Taliban bases in Northern Waziristan, and claims to have cleared nearly two-thirds of the area. Indeed, the attacks at the schools in Charsadda and Peshawar are the Taliban’s crazed and desperate response.

We can only hope that the success of the Pakistani military in its fight against the Taliban continues. That fight is a long time coming.