The war in Afghanistan—18 years old and still raging, at a cost of nearly $1 trillion, 2,300 U.S. troops killed, and more than 20,000 injured—has been a muddle from the beginning, steered by vague and wavering strategies, fueled by falsely rosy reports of progress from the battlefield, and almost certainly doomed to failure all along.

This is the inescapable conclusion of a secret U.S. government history of the war—consisting of 2,000 pages, based on interviews with more than 400 participants—obtained and published by the Washington Post on Monday after years of legal battles to declassify the documents.

Written by the Office of the Special Inspector General for Afghanistan Reconstruction, an agency created by Congress in 2008 to investigate waste and fraud, the report, titled “Lessons Learned,” is the most thorough official critique of an ongoing American war since the Vietnam War review commissioned in 1967 by then–Secretary of Defense Robert McNamara. (Daniel Ellsberg leaked what came to be known as the Pentagon Papers in 1971; though widely disseminated, they were officially declassified only in 2011.)

The “Afghanistan Papers,” as the Post dubs the report, is narrower in scope than McNamara’s project; the latter delved into the entire history of U.S. involvement in Vietnam and incorporated top-secret memos and other documents from throughout the national security bureaucracy. Still, the new report resonates with the same dread and melancholy about a war built on ignorance, lies, and counterproductive policies.

Central to the current war effort—and to its failure—was corruption. It was central because the Afghan government couldn’t defeat the Taliban insurgents, or win the support of its people, as long as it was corrupt from top to bottom. The United States failed because the billions of dollars we poured into the country only made Afghanistan’s corruption worse.

The United States failed because the billions of dollars we poured into the country only made Afghanistan’s corruption worse.

Ryan Crocker, former ambassador to Afghanistan and Iraq, told the investigators in a 2016 interview, “You just cannot put those amounts of money into a very fragile state and society, and not have it fuel corruption.” He added that the same thing happened in Iraq, where corruption is “pandemic and deeply rooted” and where “it’s hard to see how a better political order can ever be established.”

A big problem, Crocker said, was a perennial “American urge,” when intervening in a foreign conflict, to “start fixing everything as fast as we can.” We pour in billions of dollars, which wind up in the hands of the powerful—the report estimates that 40 percent of U.S. aid to Afghanistan was pocketed by officials, gangsters, or the insurgents themselves—who become more corrupt still.

The U.S. military dedicated enormous effort to training the Afghan special forces. Those forces “can clear an area” of insurgents, Crocker said. The problem is that they would then turn the area over to the Afghan police, who couldn’t hold on to it, “not because they’re outgunned or outmanned” but rather “because they are useless as a security force”—and they’re useless “because they are corrupt down to the patrol level.”

Sarah Chayes, who served as an adviser to the chairman of the Joint Chiefs of Staff and who lived in Afghanistan for several years, told the investigators in 2015 that the problem was rooted in Washington. Fighting terrorism was the chief U.S. mission, and some officials understood that corruption is a cause of terrorism. But, Chayes said, the notion “hasn’t sunk in enough for the causal flip to happen”—i.e., for the officials to see that countering corruption had to be a key ingredient in countering terrorism.

A major obstacle here, she said, was the “culture” in the State Department and the Pentagon, which focused on building relationships with their counterparts abroad. Since Afghan officials at all levels were corrupt, officials feared that going after corruption would endanger those relationships.

Chayes also said it was a big mistake to be “obsessed with chasing” the Taliban, to the point of neglecting the country’s political dynamics. We didn’t realize that many Afghans were “thrilled with the Taliban” for kicking corrupt warlords out of power. Instead, we aligned ourselves with the warlords, on the adage that “the enemy of our enemy is our friend”—and, as a result, further alienated the Afghan people and further enriched the corrupt powers, which in turn further inflamed the anti-government terrorists.

Christopher Kolenda, a retired U.S. Army colonel who was a strategic adviser to three U.S. commanders in Afghanistan, told the investigators in 2016 that the problem was more deeply rooted still. He described the Afghan government as a “kleptocracy”—an entity whose main activity was looting. The vast mounds of American money, brought into the country by the military and aid agencies, only further enriched the kleptocracy, deepened its hold on power, and deepened the insurgency against it.

“It was through sheer naivete, and maybe carelessness, that we helped to create the system,” Kolenda said. He added, “Foreign aid is part of how” the Afghan kleptocrats “get rents to pay for the positions they purchased.”

What makes this syndrome all the more tragic is that it was recognized long ago, and even publicly discussed. In September 2009, as the Obama administration was debating a new policy toward the Afghanistan war, Adm. Mike Mullen, chairman of the Joint Chiefs of Staff, testified at a Senate hearing that the main problem “is clearly the lack of legitimacy of the government” in Kabul.

Sen. Lindsey Graham pushed the issue. “We could send a million troops, and that wouldn’t restore legitimacy in the government?” he asked.

“That is correct,” Mullen replied. The threat of corruption, he added, “is every bit as significant as the Taliban.”

Even so, the implications weren’t fully grasped. When his questioning time was up, Graham thanked Mullen for his service and said, “I believe we can win, and we must”—neglecting to ask what “win” might mean. Around this same time, during the closed-door National Security Council sessions, Mullen was urging President Barack Obama to send 40,000 more U.S. troops to fight the war and to create a counterinsurgency strategy based on helping the Afghan government win the hearts and minds of its people—not addressing how to do this, if the government lacked legitimacy.

Almost all of Obama’s advisers sided with Mullen, a notable exception being Vice President Joe Biden, who thought counterinsurgency wouldn’t work (it didn’t) and instead advised sending just 10,000 more troops to help further train the Afghan army (which is what Obama wound up doing after first giving the troop surge a chance for 18 months).

When Gen. David Petraeus became commander of U.S. troops in Afghanistan in 2010, he appointed an anti-corruption task force. (Sarah Chayes was one of its members.) The task force concluded that corruption, from Kabul on down, was impeding the war effort and that the U.S. should cut off aid to the entire network of corruption. Petraeus sympathized with the findings, but he needed Afghan President Hamid Karzai’s cooperation to fight the war at all, and so he rejected the recommendation.

Petraeus had a point, but it only highlighted the war’s inherent futility. We were fighting terrorism, but, as Chayes put it, “corruption is creating the terrorists”—a fact that U.S. officials were “still not getting.”

The way we fight insurgents in countries with fragile states and societies tends to strengthen our enemy—and, to the people struggling to survive in those countries, we become the enemy. Until this is recognized and remedied, it’s better not to intervene in the first place.