If leaving Afghanistan were easy, it would probably have been done a long time ago. Four presidents have presided over the 20-year war. Three have said they wanted to get out. None, until President Biden, were willing to pull the plug and face the consequences.

So America stayed in, spending a trillion dollars and losing thousands of lives for what we’re finding out was a failure in nation-building.

Why did America pursue a war it didn’t want to fight? The answer, according to experts, is that its leaders were caught between the politics of an unpopular conflict and the reality of an intractable conflict that could make America less safe if it ended.

“What they all realized was almost all the options we had for leaving would ultimately create an unstable Afghanistan where no one could predict what was going to happen next,” said Anthony Cordesman, a Middle East policy expert now at the Center for Strategic and International Studies. “And the cost of getting out would be that failure.”

Here’s a brief history of America’s longest war through the lens of the decisions and statements of the four presidents who presided over it.

Bush: From hunting 9/11 terrorists to nation-building

This part of the story is well-known. America was attacked on Sept. 11, 2001, and then-President George W. Bush invaded Afghanistan and Iraq to find the attackers.

He had the support of Congress and much of the public for his mission, but he was forging a new conflict in a strange land, and that lent itself to plenty of mistakes, said Emily Harding, an intelligence expert now at CSIS.

“I know some of the guys who were in on the first wave,” she said. “And they went in with a pocket knife and a prayer to say: ‘We’re going to try to find somebody we can work with who can help us find al-Qaeda and get rid of them.’ ”

They did. “That mission went extraordinarily well,” Harding said.

The Bush administration had hoped that after the bad guys were run out of Afghanistan, they could safely hand the keys of power back to Afghans. They quickly realized that was impossible, and they got stuck in the country with no clear path on what to do next, Harding said.

Bush pivoted to nation-building. He sold it as the next, necessary step in his war on terror. “By helping to build an Afghanistan that is free from this evil and is a better place in which to live, we are working in the best traditions of George Marshall,” he said as he announced a Marshall plan of his own for Afghanistan.

Bush’s optimism in Afghanistan was underpinned by a belief that democracy would flourish when given the opportunity. “The survival of liberty in our land increasingly depends on the success of liberty in other lands,” he told Congress in 2005.

When Bush left office in 2009, there were about 25,000 troops in Afghanistan. And the war was about to escalate.

Obama: Ramping up to ramp down

Former president Barack Obama campaigned on his opposition to the invasion of Iraq and his skepticism of the war on terror more broadly. Yet in office, he presided over the largest troop presence in Afghanistan and a false declaration that the war was over.

Obama ended the war in Iraq and aimed to do the same in Afghanistan. His strategy was to ramp up so he could ramp down. He initiated several surges of tens of thousands of troops there, at one point reaching 100,000 as violence escalated.

Obama also called for an end to combat there in 2014, and when that date came, he declared the fighting was over. “[O]ur combat mission in Afghanistan is ending and the longest war in American history is coming to a responsible conclusion,” he told Americans at the end of that year.

But The Washington Post’s Craig Whitlock reports that the Obama administration’s assertion that the fighting had ended was “among the most egregious deceptions and lies that U.S. leaders spread during two decades of warfare.” The war was nowhere near done, and Obama wasn’t willing to actually end it, lest he face exactly what Biden is facing right now.

A hugely symbolic moment in the war on terror did come under Obama: The United States found and killed Osama bin Laden, the mastermind of the 2001 terrorist attacks, after a decade on the run.

When Obama left office in 2017, there were about 9,000 troops on the ground in Afghanistan.

Trump: Let’s just get out

By the time Donald Trump came into office in 2017, he — and much of the American public — were so over this war. He upended the Republican Party in part by attacking Bush and other establishment Republicans for their handling of foreign policy in general and, specifically, for pursuing “endless wars.” He promised to bring the troops home.

“Are they going to be there for the next 200 years? At some point, what’s going on?” he said in 2015 on the campaign trail.

Trump signed a peace agreement with the Taliban that said the United States would leave in about a year, and in exchange the Taliban would promise not to let Afghanistan harbor terrorists who would launch attacks on America.

“I really believe the Taliban wants to do something to show that we're not all wasting time,” Trump said, continuing a tradition of American presidents offering rosy assessments that didn’t match reality in Afghanistan. Almost as an aside, he added this: “If bad things happen, we’ll go back with a force like no one’s ever seen.”

But Trump failed to publicly share that there was no enforcement mechanism to keep the Taliban from harboring terrorists, and signs pointed to them doing just that, recounts Paul Miller, a veteran of Afghanistan now teaching at Georgetown University, in the Dispatch.

Trump drew down troops in Afghanistan to 2,500. But even he didn’t officially end the war.

Biden: “We’re ending America’s longest war.”

By the time Biden came into office, the American debate on whether to withdrawal had been settled, and Biden was the president to actually do it.

Biden reversed many of Trump’s international agreements. But Trump’s peace deal with the Taliban he notably kept. America would be out of Afghanistan by the 20th anniversary of the Sept. 11, 2001, attacks.

No war was worth this cost, Biden argued.

“[T]he United States did what we went to do in Afghanistan: to get the terrorists who attacked us on 9/11 and to deliver justice to Osama bin Laden, and to degrade the terrorist threat to keep Afghanistan from becoming a base from which attacks could be continued against the United States. We achieved those objectives. That’s why we went,” he said in July. “We did not go to Afghanistan to nation-build. And it’s the right and the responsibility of the Afghan people alone to decide their future and how they want to run their country.”

Even Republican hawks acknowledge that there was no political will to stay in Afghanistan. Where Biden is facing intense heat and criticism now is in the execution of the final withdrawal, which has been chaotic, as Biden and his administration were caught flat-footed by the swift collapse of the Afghan government.

Intelligence was warning that the Taliban could take over in as soon as six months. Yet in July, as a resurgent Taliban advanced toward Kabul and Americans shuttered military bases, Biden assured Americans: “The likelihood there’s going to be the Taliban overrunning everything and owning the whole country is highly unlikely.”

The Taliban overran the country even before the U.S. military officially left.

Both Republicans and Democrats say they’re frustrated that Biden failed to plan for a worst-case scenario and for how to get the United States’ Afghan allies out of the country before the Taliban took over.

Despite doing what no other president was willing to do, Biden was arguably the most disingenuous about what the consequences would be in ending the war, some analysts say.

“I just find it amazing to say you didn’t realize you could have a catalytic collapse,” Cordesman said, “to deny a Vietnam-like case as possible … that borders on just plain lying.”

The legacy of the Afghanistan war is one for the history books, to be debated and studied for years to come. And Biden’s bungled withdrawal could add a new chapter, depending on how events play out in the coming days and weeks. But the shared experiences of four very different presidents — and the evolving justifications for two decades of costly and increasingly unpopular conflict — suggest that there will be little political appetite for American military intervention in faraway nations.