Say this much about President Obama: He does not engender a lot of loyalty from his inner circle.

First Robert Gates published a memoir in which he declared that Obama “doesn’t believe in his own strategy [in Afghanistan], and doesn’t consider the war to be his. For him, it’s all about getting out.”

Then Hillary Rodham Clinton declared during the book tour for her memoir that Obama’s “failure” to arm and train Free Syrian Army rebels “left a big vacuum, which the jihadists have now filled.”

Now comes Leon Panetta with a new memoir, “Worthy Fights,” in which he lays responsibility for the withdrawal of U.S. forces and the rise of the Islamic State where it belongs — directly at Obama’s feet.

Panetta writes that he warned Obama of the danger of withdrawing all U.S. troops from Iraq: “My fear, as I voiced to the President and others was that if the country split apart or slid back into the violence that we’d seen in the years immediately following the U.S. invasion, it could become a new haven for terrorists to plot attacks against the U.S.” But when he and Obama’s military commanders recommended keeping 24,000 troops, “the President’s team at the White House pushed back, and the differences occasionally became heated.” The White House, Panetta says, was “so eager to rid itself of Iraq that it was willing to withdraw rather than lock in arrangements that would preserve our influence and interests.” Now, “the ISIS offensive in 2014 greatly increases the risk that Iraq will become al-Qaeda’s next safe haven. That is exactly what it had in Afghanistan pre-9/11.”

Vice President Biden slammed Panetta for his “inappropriate” criticism, declaring he should have “at least give[n] the guy a chance to get out of office.”

But it is precisely because Panetta did not wait until Obama left office that his criticism is appropriate. His book is not simply the latest contribution to the blame game over what went wrong in Iraq. It is a prescient warning about the future — because Obama is about to make the exact same mistake in Afghanistan.

In May, Obama announced that he would withdraw all U.S. forces from Afghanistan by the end of 2016, leaving only a tiny force to protect the U.S. Embassy in Kabul. And last week, as the United States signed an agreement to extend the American presence beyond this year, National Security Council spokeswoman Caitlin Hayden reiterated that the administration had “no plans to change the plan the president announced” for a complete Afghan withdrawal by the end of 2016.

Well, if we withdraw all our troops from Afghanistan as we did in Iraq, then we will have the exact same result that we now have in Iraq. The terrorists will use the vacuum left by the U.S. withdrawal to regroup, reconstitute themselves and reestablish the safe haven they lost in that country. Indeed, they will do so far more quickly in Afghanistan than they did in Iraq — because the Taliban is nowhere near as defeated in Afghanistan today as the Islamic State was when Obama withdrew U.S. forces from Iraq.

This will leave the United States with a far worse situation than before the terrorist attacks of Sept. 11, 2001. Before 9/11, the terrorists had safe haven in one country. Now they will now have safe havens in three countries — Iraq, Syria and Afghanistan. And that’s not counting Yemen (where al-Qaeda-linked militants just launched a rocket attack on our embassy and the government is near collapse) or Libya (where Islamists have taken over, forcing the United States to evacuate its embassy). The various terrorist factions will then fight for dominance in the jihadist world by competing to see who can be the first to attack us here at home.

This is why, instead of attacking Panetta, the White House should be listening to him. Panetta is a liberal Democrat, and at 76, his public life is largely behind him. He is not angling for the next job. If anything, it is an indictment of the administration that he felt the need to make his criticisms public — because Obama and his team apparently would not listen privately.

They need to listen now — because if the president does not understand how the disaster he created in Iraq unfolded, he is destined to create a similar disaster in Afghanistan.

And that would be a disaster for the United States.

Read more from Marc Thiessen’s archive, follow him on Twitter or subscribe to his updates on Facebook.