President Trump has made no secret of his aversion to foreign military entanglements, and he pledged to get the troops out. It’s an election year, but the politics of the moment should not obscure the fact that ending American involvement in the war is the right thing to do. And, unlike the precipitous withdrawal of American troops from northern Syria, this pullout catches no one by surprise. By November, the number of American troops remaining in Afghanistan should be well down from the current 12,000 or so, and the Taliban will most likely still be abiding by the deal to make sure the staged withdrawal continues until all the foreign troops are gone.

Though not involved in the talks, the Afghan government has been aware of the negotiations, and, under the agreement, the Americans will continue funding and supporting the Afghan military. That the military is in shambles after 18 years of American tutelage, and that the government of Afghanistan is deeply corrupt and bitterly contested since a disputed election, only underscore that brute military force by an outside power is helpless against deep-seated ethnic and ideological divisions. And propping up an Afghan government was not the reason the United States went to war there.

The reason was the 9/11 terrorist attacks, and the pressure to go after those responsible for so horrific an outrage. Afghanistan, much of it controlled by the staunchly Islamist Taliban, had provided sanctuary for Osama bin Laden, and so that is where American troops headed to wage President George W. Bush’s “war on terrorism” — and to seek retribution.

But the mission soon became fuzzy. By the time Bin Laden was hunted down in May 2011 — in Pakistan, and not in the Tora Bora caves of Afghanistan where Al Qaeda and Taliban had their strongholds — Al Qaeda was already a much weaker force, and the Taliban had been long driven from power. Yet American and allied forces remained.

The full futility of that effort was revealed in documents obtained by The Washington Post late last year from an investigation by the Special Inspector General for Afghanistan Reconstruction. They showed how for years, even as American government officials were claiming successes in building a democratic government in Afghanistan, the military and civilian officials on the ground acknowledged the obvious — that it was an extraordinarily expensive — roughly $2 trillion over 18 years — and pointless exercise. Their unvarnished pronouncements, withheld from the public, were devastating: “I have no visibility into who the bad guys are,” wrote Donald Rumsfeld, the secretary of defense when the war began, in 2003. Twelve years and many billions of dollars later, Gen. Douglas Lute, an Army general who served in the Bush and Obama administrations, told the inspector general, “We didn’t know what we were doing.”