Lindsey Graham is a Republican senator from South Carolina. Jack Keane, a retired general, is chairman of the Institute for the Study of War and was vice chief of staff of the U.S. Army.

President Trump’s desire to end the war in Afghanistan is understandable. After 18 years of war, the current path is not sustainable.

Nevertheless, we may be in such a rush to remove our forces that we find ourselves on the cusp of a strategic blunder. Any deal that calls for withdrawing our forces completely from Afghanistan is a bad deal for the United States.

We must be clear: The United States should never outsource its national security to anyone, especially the Taliban. That is a possible outcome, however, as the United States and the Taliban continue talks in Doha, Qatar. We cannot rely on the Taliban for security; we have lost too many soldiers at Taliban hands for that. The Afghan war must end on our terms, not the Taliban’s.

The United States entered Afghanistan in 2001 for one reason: to run al-Qaeda out of its haven and ensure that it was never able to attack America again. We achieved that objective in 2002 and have sustained it since with the United States, NATO and other partner nations.

U.S. force levels have ebbed and flowed since 2002, but we now have less than 15 percent of the forces we had at our peak in 2011. The tasks that used to be solely the responsibility of U.S. and NATO and partner forces are now in the hands of the Afghan National Defense and Security Forces.

Afghan forces are shouldering the burden of the fighting and have lost tens of thousands of soldiers and police in recent years protecting their country. We will have the ability to reduce our presence further as Afghan forces become more capable. But if U.S. forces leave now, before Afghans are ready to stand by themselves, we will be abandoning them when they still need our support.

Most importantly, American national security interests require that any agreement allow a meaningful U.S. counterterrorism capability, coupled with a robust intelligence apparatus, to remain in Afghanistan to deal with the real threats that will continue from groups such as the Islamic State’s Afghan affiliate, ISIS-K. It is equally critical that this force stay until the defense secretary and the secretary of state certify to Congress that withdrawing troops from Afghanistan will not put the United States homeland and our interests at risk of another terrorist attack.

We can never forget that when the Taliban took control of Afghanistan in 1996, they took the country backward, destroying prosperity, oppressing women and operating with a total disregard for basic human rights. They also welcomed Osama bin Laden and al-Qaeda as honored guests. Bin Laden used his newfound freedom in Afghanistan to plan, prepare and direct the attacks against two U.S. Embassies in Africa in 1998, the USS Cole in Yemen in 2000 and the 9/11 attacks that killed nearly 3,000 Americans.

Following 9/11, President George W. Bush demanded that the Taliban hand bin Laden over or face the destruction of their regime. The Taliban refused to give him up and instead decided to stand with al-Qaeda. Today, they have yet to repudiate al-Qaeda. Even if they take that step publicly as part of a deal with the United States, there is no credible evidence that they would mean it.

The United States cannot contract out the American people’s security to the Taliban who, in exchange for a U.S. withdrawal, simply “promise” to guarantee that al-Qaeda and ISIS-K are denied haven.

Finally, we fear that a “U.S. withdrawal deal” with the Taliban would not end the war. It is much more likely to start a new, far worse civil war as the Afghan forces would feel betrayed and abandoned, the Afghan government would be severely undermined and weakened, and the Northern Alliance would withdraw its members from the Afghan Army.

The added chaos with all U.S. troops gone would become an open invitation for al-Qaeda and the Islamic State to refocus on Afghanistan, as they both did in Syria. In the midst of such a civil war, Taliban promises to keep al-Qaeda out will mean less than nothing — they would not be able to fulfill them even if they wanted to.

History has taught that how we end a conflict is more important than how we start one. If we don’t end this war properly, we won’t be ending it at all. Instead, we will be creating a much worse situation for everyone except for groups such as the Taliban, al-Qaeda and the Islamic State.

Read more:

David Ignatius: Lindsey Graham wants to create a backstop for Afghanistan

The Post’s View: Trump risks turning a chance for success in Afghanistan into a shameful failure

Jarrett Blanc: We need to take the best deal we can get in Afghanistan

Tanya Goudsouzian: Yes, the Taliban has changed — it’s gotten much better at PR

David Ignatius: Uncertainty clouds the path forward for Afghanistan