Democrats are roasting President Trump this week for his cancellation of a planned summit with Taliban leaders whose aim was to finalize a peace deal for Afghanistan. Presidential candidate Amy Klobuchar said Trump was conducting foreign policy as if it were “a game show.”

But the bottom line about Trump’s decision is that it was correct.

Negotiating with the Taliban is a bitter pill for Americans to swallow. These brutal Islamist killers have the blood of nearly 2,000 Americans on their hands, as well as that of countless numbers of Afghans. But after nearly 18 years of a stalemated war and a doomed effort to democratize Afghanistan, the administration was obligated to seek an alternative.

The goal of the talks was clear.

Yet this is not just an obscure fight that warmongering hawks dragged the country into. American security is on the line there, since the first objective must be to guarantee that Afghanistan will never again serve as a haven for terrorists as it did for al Qaeda before 9/11.

It’s also important for Washington to not sign a deal that will allow it to betray the Afghan government. Nor should we let the Taliban take over all of the country and return its tortured people to medieval barbarity after a decent interval has passed between the American withdrawal and the return of the Islamists to power in Kabul.

For the United States to be complicit in a scheme that will allow the women and children of that country to be abandoned to the tender mercies of Taliban murderers would be a dishonorable conclusion to this longest of all of our wars.

Is it possible for Washington to satisfy both of those concerns? That remains to be seen, but Trump shouldn’t be faulted for trying even if the effort is doomed to failure.

Some Democrats are also arguing that Trump’s blaming of the collapse of the talks on last week’s car bomb attack that cost the life of a US soldier was an excuse that covered up his uncertainty about whether a potential agreement with the Taliban was the right thing to do.

But whether or not that is true — and it’s clear that the Taliban have no intention of stopping their terrorist attacks — Trump was right to call a halt to the entire exercise once he understood that the outcome would neither ensure America’s security nor those of the people he’s proposing to leave behind.

The problem here is not Trump’s theatrical style but a process that doesn’t seem likely to accomplish anything but give the United States a diplomatic fig leaf to cover up a desire to bug out and leave a mess behind that will soon come back to bite us.

We have two recent examples of a president conducting foreign policy in a more conventional manner with terrible results.

President Barack Obama was so desperate for a nuclear deal with Iran at any price that he accepted one that didn’t ensure Tehran would never get a nuclear weapon or use the wealth it received in exchange for the agreement to fund terrorism and various hostile foreign adventures.

Similarly Obama was so eager to proclaim that he had ended the war in Iraq with a stroke of his pen that he didn’t consider the consequences of a unilateral withdrawal. The resulting power vacuum he left behind led to the rise of ISIS and more suffering and bloodshed.

However he arrived at his decision, Trump seems to have belatedly realized he was mistaken and, in contrast to Obama’s arrogance, pulled the plug on a disaster in the making before it was too late.

While a dramatic gesture like holding talks at Camp David appealed to Trump, it was still a mistake. Canceling it was the beginning of wisdom.

There’s more to achieving America’s objectives or ending a war where the other side intends to go on fighting than signing a piece of paper. President Trump’s pull-back from the brink of repeating Obama’s mistakes may strike Democrats as undignified, but it is far better than sticking with a deal that would have been a humiliating defeat for US interests.

Jonathan Tobin is editor in chief of JNS.org and a contributor to National Review.