An Indian soldier stands guard near the Pathankot airbase, shortly after the base was seized by Pakistani militants. Photograph by Channi Anand / AP

Imagine a country that is embroiled in a long and bloody conflict with its neighbor, and each time its democratically elected Prime Minister tries to reach out and make peace, his own army launches an attack to make sure the peace doesn’t take hold. You might think you were trapped inside a dystopian movie. Unless, of course, you’ve been to Pakistan, where this happens all the time.

This week, Pakistani officials said they had detained Masood Azhar, the leader of Jaish-e-Mohammed, a militant group, for his alleged role in overseeing the attack on an Indian airbase in the city of Pathankot earlier this month. The attack left seven Indians dead. Jaish-e-Mohammed is one of several Pakistani militant groups whose members routinely cross into India and carry out attacks there, for the ostensible purpose of prying loose Jammu and Kashmir, India’s only Muslim-majority state.

Azhar’s detention is almost certainly a farce, staged to placate foreign leaders. If the past is any guide, Azhar, who has been detained many times before, will soon be free and able to carry out more attacks. This is the way it has worked in Pakistan for years.

The attack on the airbase in Pathankot, on January 2nd, came little more than a week after the Indian Prime Minister, Narendra Modi, flew to Lahore to meet the Pakistani Prime Minister, Nawaz Sharif, for a surprise summit. It was the first visit by an Indian leader to Pakistan in twelve years. By all accounts, the meeting went well. That’s an unqualified good; both countries possess nuclear weapons, and their unresolved disputes, especially over Kashmir, could have terrifying consequences. India and Pakistan have already been to war with each other four times.

So why would Pakistani-based fighters follow up a feel-good summit with a cross-border attack? Well, it wouldn’t be the first time, or the second, or even the third.

In 1999, Indian Prime Minister Atal Bihari Vajpayee took a bus across the border to meet Sharif, and the two men pledged that peace would prevail between their two countries. Less than three months later, Pakistani soldiers, dressed up like jihadis, crossed the Indian border in the Himalayas and captured several Indian army posts. The Indian army repelled the invaders but the fighting, centered around the town of Kargil, came dangerously close to spinning out of control. It doesn’t appear that the Pakistani military, which orchestrated the attack, ever bothered to ask Sharif for permission.

In July, 2001, Vajpayee invited the Pakistani dictator Pervez Musharraf, who had recently declared himself Chief Executive after seizing power from Sharif in a military coup, to the Indian city of Agra to talk peace. Three months later, Pakistani-based guerrillas mounted an assault on the Jammu and Kashmir State Assembly building, and two months after that they launched a brazen attack on the Indian Parliament in New Delhi. Indian troops were nearly ordered to cross the border, but the crisis was defused.

In September, 2008, Pakistan’s first elected leader in nine years, President Asif Zardari, made a series of peaceful overtures to India. Two months later, Pakistan-based terrorists attacked the Taj Mahal Palace Hotel and other targets in Mumbai, killing more than a hundred and fifty people and wounding more than three hundred.

I’m not the first person to notice that Pakistani militants regularly try to sabotage peaceful relations between their country and India. Aparna Pande, at the Hudson Institute, has put together a chronology of these attacks.

But the important point is who backs, trains, tolerates and supports those militants: the Pakistani military and, most particularly, its spy service, known as the Inter-Services Intelligence, or the I.S.I.

For decades, the Pakistani military has backed insurgent groups whose express aim is to cross into India and fight. (The I.S.I. has also done this in Afghanistan, helping to create and sustain the Taliban.) The ostensible aim of these militant groups, and of the I.S.I., is to bleed India into ceding control over Kashmir. This has never been more than a fantasy, but it keeps the country of Pakistan focussed on something other than its intractable domestic problems, and it justifies the military’s bloated budgets.

That the I.S.I. plays godfather to groups like Jaish-e-Mohammed, which appears to have carried out the Pathankot attack, and Lashkar-e-Toiba, which launched the operation in Mumbai—the assault on the Indian Parliament appears to have been a joint operation of the two—is beyond doubt. It has been chronicled in great detail by the Pakistani journalist Ahmad Rashid, the former Pakistani ambassador to the United States Husain Haqqani, and the former C.I.A. and N.S.C. analyst Bruce Riedel. Indeed, in the attacks on Mumbai and the Parliament, there was evidence that I.S.I. officials had provided direct support.

The attack on the base in Pathankot has especially lurid implications. Masood Azhar, who appears to have overseen it, was once imprisoned in India on charges of kidnapping Westerners there. In 1999, he was released at the demand of a group of terrorists—from yet another Pakistani-backed group—who hijacked Indian Airlines flight 814 and landed it in Afghanistan, which was then under Taliban rule. Once Azhar was released, I.S.I. encouraged him to set up his group Jaish-e-Mohammed, according to Rashid. (Among the others released from the Indian prison that day was Omar Saeed, the British-Pakistani militant who was later convicted for kidnapping and murdering the Wall Street Journal reporter Daniel Pearl.) Shortly after Azhar’s release, with the I.S.I. at his side, he toured Pakistan, raising money for the jihad against India.

Did the Pakistani military order Azhar to attack the Indian airbase in Pathankot? Maybe, maybe not. “The Pakistan Army feels like they can control these groups, but they have a mind of their own,” Haqqani told me. “They do what they want. Do they get a wink and a nod from the military? It seems quite likely.”

When Pakistani officials announced this week that they had detained Azhar on suspicion of involvement in the Pathankot attack, it raised the obvious question: How did they know where he was?

What is most remarkable is that the pattern never changes. The Pakistani military keeps backing militant groups, like Jaish-e-Mohammed, that keep pushing the subcontinent to the brink of war, and that keep undermining Pakistan’s fledgling democratic institutions.

Since 9/11, according to congressional reports, U.S. taxpayers have given Pakistan at least eighteen billion dollars, much of it to the military. Last year alone, the U.S. gave Pakistan $1.5 billion dollars. Isn’t it about time we asked ourselves whether this is a good idea?