Two months after the 2008 U.S. presidential election, Vice President–elect Joe Biden sat with Afghanistan’s president, Hamid Karzai, in the Arg Palace, an 83-acre compound in Kabul that had become a gilded cage for the mercurial and isolated leader. The discussion was already tense as Karzai urged Washington to help root out Taliban sanctuaries in Pakistan, implying that more pressure needed to be exerted on Pakistani leaders. Biden’s answer stunned Karzai into silence. Biden let Karzai know how Barack Obama’s incoming administration saw its priorities. “Mr. President,” Biden said, “Pakistan is fifty times more important than Afghanistan for the United States.”

It was an undiplomatic moment for sure, but also a frank expression of the devastating paradox at the heart of the longest war in American history. In 16 years, the United States has spent billions of dollars fighting a war that has killed thousands of soldiers and an untold number of civilians in a country that Washington considers insignificant to its strategic interests in the region. Meanwhile, the country it has viewed as a linchpin, Pakistan—a nuclear-armed cauldron of volatile politics and long America’s closest military ally in South Asia—has pursued a covert campaign in Afghanistan designed to ensure that the money and the lives have been spent in vain. The stakes in Pakistan have been considered too high to break ties with Islamabad or take other steps that would risk destabilizing the country. The stakes in Afghanistan have been deemed low enough that careening from one failed strategy to another has been acceptable.

Even so, the post-9/11 years have seen the slow dissolution of the shotgun marriage arranged between the U.S. and Pakistan in the quest to rout al-Qaeda. As Steve Coll recounts in Directorate S—which picks up the narrative where his Pulitzer Prize–winning 2004 volume, Ghost Wars, left off—the seeds of mistrust were planted early, and mutual recriminations steadily accumulated. Weeks after the 2011 raid that killed Osama bin Laden, a demoralized Ashfaq Parvez Kayani, the head of Pakistan’s army, likened his “helpless” country to a mortgaged house, with the United States playing the role of banker. For American officials who dealt with Pakistan, another domestic analogy might have seemed more apt: Pakistan was the spouse who had drained the family bank account and then slept with the sketchy neighbor.

The anger on the American side was fueled by the gradual realization that Washington had, since the very beginning of the war, allowed Pakistan to wield too much influence over U.S. strategy. As the Taliban retreated from Kabul and Kandahar in late 2001, the CIA station chief in Islamabad wrote cables channeling the Pakistani military’s perspective. A Northern Alliance takeover of the country, the message went, could lead to a bloodbath for Afghanistan’s Pashtuns (Pakistan’s traditional allies) and undermine Pakistan’s readiness to broker a political settlement there. What Pakistan wanted most of all, of course, was its own favored groups, and not its rival India’s, in power.

George W. Bush’s war cabinet was already jittery about the “nightmare scenario” of the new conflict: violence spilling over into Pakistan, President Pervez Musharraf’s government collapsing, and the country’s nuclear arsenal falling into the hands of Pakistani generals with Taliban sympathies. Musharraf himself spent years masterfully stoking these fears. He often warned American officials that the more he acceded to Washington’s demands, the more his support inside the military would erode and the better the chances would become of the nightmare scenario playing out.

The conundrum might have been resolved, Coll suggests, had the American military’s tactical failures during the first year not helped Musharraf’s argument that Pakistan was too dangerous to ignore. Intelligence failures and insufficient troops at the battles in Tora Bora and the Shah-i-Kot Valley allowed al-Qaeda fighters to slip over Afghanistan’s eastern border and resettle in Pakistan’s tribal areas and cities. With the arrival of the militants in his country, Musharraf ordered his military intelligence service, the ISI, to work with the CIA to hunt down al-Qaeda’s leaders in Pakistani cities. He also made the case to U.S. officials that, partly thanks to American misadventures, Pakistan now deserved a huge influx of military aid. The arrests in 2002 and 2003 of Abu Zubaydah, Khalid Sheikh Mohammed, and others reinforced Bush’s view that Pakistan was “with us,” an ally to be trusted.

Coll convincingly shows that those few al-Qaeda scalps, delivered by the ISI at a time when the Bush administration had already begun to ignore Afghanistan and focus on the looming war in Iraq, bought years of American inattention to the ISI’s more secretive activities: arming and financing the Taliban and other Afghan militant groups sympathetic to Pakistan rather than India. The United States had stumbled into an informal, unspoken bargain, accepting help from Pakistan in the fight against al-Qaeda in exchange for tacitly enabling, while feebly contesting, Pakistan’s efforts to sabotage the American-led campaign in Afghanistan. Intermittent U.S. demands that the covert efforts stop went unheeded.

The deal was stunningly lucrative for Islamabad. Each year, the Pentagon transferred hundreds of millions of dollars in cash to Pakistan, ostensibly to reimburse its military for counterterrorism operations. In fact, Coalition Support Funds were a “kind of legal bribery to Pakistan’s generals,” Coll argues. The Pentagon would receive bills for air-defense expenses, even though al-Qaeda had no air force. One Special Forces colonel, Barry Shapiro, recalls invoices from Pakistan’s navy listing per diem pay for sailors “on duty fighting the Global War on Terrorism.” Shapiro tried to question some of the expenses: Was there any proof that the Pakistani army had indeed shot off the missiles it was asking to be reimbursed for? But he was told by his superiors to be quiet and pay up.

The arrangement was effectively on autopilot as the Iraq War consumed the Bush administration’s attention. Congress approved the funding with few reservations, and years passed before lawmakers seemed to comprehend their role in the farce. During one congressional hearing in 2012, a top Democrat on the House Foreign Affairs Committee, Gary Ackerman, lamented that Pakistan had become “a black hole for American aid.” “Our tax dollars go in. Our diplomats go in, sometimes. Our aid professionals go in, sometimes. Our hopes go in. Our prayers go in,” he said. “Nothing good ever comes out.”

Members of Congress began calling for a strategy to put pressure on Pakistan by cutting annual aid to the country, but policy makers faced another quandary: As the goals the United States set in Afghanistan grew more ambitious, Washington’s need of Pakistan’s help to achieve them grew too. The swiftness with which the initial military campaign fulfilled its comparatively modest aims—to avenge the September 11 attacks by destroying al-Qaeda’s base in Afghanistan, expel the Taliban from cities, and install a more competent government in Kabul—led to hubris about what was possible in a hopelessly poor country wracked by decades of war.

The enterprise of nation building meant, in no particularly consistent order, quixotic attempts to root out corruption, lean on Karzai to sack unsavory warlords, and reengineer Afghanistan’s opium economy by getting farmers to plant crops far less lucrative than poppies. In 2004, I traveled with a team of Green Berets through gorgeous, flowering poppy fields to meet with the elders of various villages in Kunar province. “The government in Kabul wants you to plant wheat” was high on the list of the soldiers’ talking points. During the meeting, one of the elders duly declared, “Next year we will plant wheat!” Many of the others sniggered.

The more the United States invested in the Afghan War, the more it seemed as if Washington was holding on to a steering wheel detached from the rest of the car. The main supply lines that kept the war machine humming—bringing fuel, food, and equipment to the rising numbers of troops in Afghanistan—ran through Pakistan. The government in Islamabad could (and did, for as long as seven months at one point) cut off the supplies, leaving convoys of trucks sitting idle between the port of Karachi and various border crossings.

Many CIA officials were skeptical that the United States should try to root out corruption, and advocated that the agency focus on trying to decimate al‑Qaeda and its sympathizers with drone strikes. During the Obama years, they clashed repeatedly with generals and policy makers beguiled by a counterinsurgency doctrine that put a premium on anti-corruption efforts. Despite ample evidence of America’s inconsistent approach, the notion that the U.S. might have no grand policy whatsoever in Afghanistan was difficult to accept for some of the key players, notably Kayani and Karzai.

They chose to fill the void with conspiracy theories. Kayani and other top Pakistani military officials believed that the United States was secretly working with Karzai’s government to bolster India’s influence in Afghanistan as a counterweight to Pakistan. Karzai subscribed to a more elaborate conspiracy: Washington was sending ever more troops to his country to gain a permanent foothold in Central Asia, from which the United States could compete against Russia and China for supremacy in the region—the Great Game redux.

But this was fevered thinking, which was partly what prompted Biden to deliver his blunt message to Karzai in the Arg Palace in 2009. That meeting came at an inflection point: A new administration was taking over, and Biden was skeptical that the Afghanistan project was worth the candle. The American economy was in crisis, and the generals were about to present the inexperienced president-elect with a costly new plan to send in thousands of additional troops.

Biden began openly proposing that Obama chart a different course. If the real problems lay in Pakistan, he asked, then why not instead use the money to keep Pakistan from imploding? At the same time, shouldn’t the U.S. think about working directly with Saudi Arabia and China—traditional allies of Pakistan—to pressure the ISI to finally end its support of the Taliban and other radical groups? Coll suggests that this thinking never gained much traction. Obama went along with the generals’ troop increase, and approved an even larger one at the end of 2009. The question of what to do about Pakistan, the phantom enemy in a failing war, went largely unanswered.

Coll’s majestic Ghost Wars tracked the CIA’s adventures in Afghanistan from the Soviet invasion, in 1979, through the eve of the September 11 attacks. Reading it was a gut-wrenching experience, with momentum building toward a climactic, dreadful outcome. Reading Directorate S is more like watching a slow-motion video of a truck going off a cliff, frame by agonizing frame. And no semblance of closure ever comes. Coll may have embarked on a full accounting of the war to its end, but history didn’t cooperate. Obama announced a plan in 2014 to conclude America’s combat operations in Afghanistan. By the time his tenure in the White House wound down, the generals had persuaded him to leave thousands of troops in the country indefinitely.

Within months of taking office, his successor—who had campaigned on scaling back America’s overseas adventures—accepted a Pentagon plan to add thousands more U.S. troops. In a speech announcing his strategy, Donald Trump ran through a familiar litany of complaints about Pakistan, capped by the demand that the country end its support for the very groups America is fighting in Afghanistan. He also called on India, Pakistan’s archenemy, to take a greater role in Afghanistan’s internal affairs—a threat evidently intended to scare Pakistani officials into backing off. Frustration mounted as the year turned, and an outraged presidential tweet denouncing years of “nothing but lies & deceit” was followed by a suspension of security assistance to Pakistan. What the repercussions might be was anybody’s guess.

Coll sums up the war as a “humbling case study in the limits of American power.” But a decade and a half after the first shots were fired, the U.S. president wasn’t exactly projecting humility, much less a newly coherent American policy.

This article appears in the March 2018 print edition of The Atlantic with the headline “The Pakistan Trap.”