You don’t establish a democracy just by holding elections, and you don’t end a war just by calling it quits. America has learned both lessons the hard way in Iraq.

U.S. warplanes are there once again, targeting the Islamic State of Iraq and Syria, or ISIS. American military “advisers” were deployed to help Kurdish troops and the flailing Iraqi army thwart the threat. ISIS jihadists claim a caliphate covering much of northeastern Syria and western Iraq, where they are killing Christians and other non-Muslims in gruesome ways.

Whether you blame this situation on George W. Bush for starting an unnecessary war or on Barack Obama for withdrawing U.S. troops prematurely may depend on your political views. I think both presidents got it wrong.

We need not mention oil or WMDs. The biggest still-unproven premise on which America went into Iraq was the notion we could midwife a democratic, anti-terrorist beachhead in a land with sectarian divisions and no democratic institutions.

Yet, the campaign became part of the war on Islamic terrorists as Iraq became a magnet for such fighters. So even if it was foolish to start the war, it became vital that we win it. After four years of spilling much blood and treasure for little gain, in 2007 we finally began to do so, thanks to the “surge” and a counterinsurgency strategy.

But it seems Obama never believed this. Even as our soldiers made hard-earned progress, he spoke of Iraq as the “wrong war”; only Afghanistan was a “just” conflict.

Obama may have been right about each war’s genesis. But by the time he became president, withdrawal from Iraq for the sake of withdrawal was the wrong decision.

History will sort out exactly how hard Obama pushed to leave several thousand U.S. troops in Iraq to help maintain the peace. Whatever happened — whether he didn’t really pursue the idea, or Iraqi Prime Minister Nouri al-Maliki simply rejected it — that now looks like the wrong move.

First, it appears our withdrawal only hastened Maliki’s turn against accommodating Iraq’s Sunni and Kurdish minorities. Sectarian rivalries are aflame again.

Second, our departure left Iraq’s army less able to repel ISIS and likely contributed to our underestimation of the jihadists’ capabilities. Obama dismissed ISIS as recently as January as “a JV team (that) puts on Lakers uniforms” and thinks that “make(s) them Kobe Bryant.” That JV team controls nearly half the country now.

Finally, our leaving Iraq has made a substantial military response to ISIS even more politically difficult — a sad irony, because terrorism in Iraq threatens the U.S. and our allies now more than ever. The danger of U.S. and European citizens going to Iraq and Syria to fight, and potentially to later bring the fight back home with them, is more dire than the one posed by Saddam Hussein.

The importance of winning a victory, rather than merely declaring one, is more often than not an argument against war. But it also explains why walking away from a conflict doesn’t end it — and why I’m afraid we haven’t seen the last of war in Iraq.