First Falluja, then Mosul, and now the oil-refinery town of Bayji. The rapid advance of Al Qaeda-inspired militants across the Sunni heartland of northern and western Iraq has been stunning and relentless—and utterly predictable. Here’s a forecast: the bad news is just beginning.

The capture of Mosul, Iraq’s second-largest city, by Sunni extremists on Tuesday is the most dramatic example of the resurgence of the country’s sectarian war, which began almost immediately after the withdrawal of the last American forces in December, 2011. The fighters who took Mosul are attached to an Al Qaeda spawn called the Islamic State of Iraq and al-Sham, or ISIS, which is now poised to carve out a rump state across the Sunni-dominated lands that stretch from western Baghdad to the Syrian border and beyond.

As I detailed in a recent piece for the magazine, Iraq’s collapse has been driven by three things. The first is the war in Syria, which has become, in its fourth bloody year, almost entirely sectarian, with the country’s majority-Sunni opposition hijacked by extremists from groups like ISIS and Jabhat al-Nusra, and by the more than seven thousand foreigners, many of them from the West, who have joined their ranks. The border between the two countries—three hundred miles long, most of it an empty stretch of desert—has been effectively erased, with ISIS and Nusra working both sides. As the moderates in Syria have been pushed aside, so too have their comrades in Iraq.

The second factor—probably the dominant one—is the policies of Nuri Al-Maliki, Iraq’s Prime Minister. Maliki is a militant sectarian to the core, and he had been fighting on behalf of Iraq’s long-suppressed Shiite majority for years before the Americans arrived, in 2003. Even after the Americans toppled Saddam, Maliki never stopped, taking a page—and aid and direction—from his ideological brethren across the border in Iran. When the Americans were on the ground in Iraq, they acted repeatedly to restrain Maliki, and the rest of Iraq’s Shiite leadership, from its most sectarian impulses. At first, they failed, and the civil war began in earnest in 2006. It took three years and hundreds of lives, but the American military succeeded in tamping down Iraq’s sectarian furies, not just with violence but also by forcing Maliki to accommodate Sunni demands. Time and again, American commanders have told me, they stepped in front of Maliki to stop him from acting brutally and arbitrarily toward Iraq’s Sunni minority. Then the Americans left, removing the last restraints on Maliki’s sectarian and authoritarian tendencies.

In the two and a half years since the Americans’ departure, Maliki has centralized power within his own circle, cut the Sunnis out of political power, and unleashed a wave of arrests and repression. Maliki’s march to authoritarian rule has fueled the reëmergence of the Sunni insurgency directly. With nowhere else to go, Iraq’s Sunnis are turning, once again, to the extremists to protect them.

Which brings us to the third reason. When the Americans invaded, in March, 2003, they destroyed the Iraqi state—its military, its bureaucracy, its police force, and most everything else that might hold a country together. They spent the next nine years trying to build a state to replace the one they crushed. By 2011, by any reasonable measure, the Americans had made a lot of headway but were not finished with the job. For many months, the Obama and Maliki governments talked about keeping a residual force of American troops in Iraq, which would act largely to train Iraq’s Army and to provide intelligence against Sunni insurgents. (It would almost certainly have been barred from fighting.) Those were important reasons to stay, but the most important went largely unstated: it was to continue to act as a restraint on Maliki’s sectarian impulses, at least until the Iraqi political system was strong enough to contain him on its own. The negotiations between Obama and Maliki fell apart, in no small measure because of a lack of engagement by the White House. Today, many Iraqis, including some close to Maliki, say that a small force of American soldiers—working in non-combat roles—would have provided a crucial stabilizing factor that is now missing from Iraq. Sami al-Askari, a Maliki confidant, told me for my article this spring, “If you had a few hundred here, not even a few thousand, they would be coöperating with you, and they would become your partners.” President Obama wanted the Americans to come home, and Maliki didn’t particularly want them to stay.

The trouble is, as the events of this week show, what the Americans left behind was an Iraqi state that was not able to stand on its own. What we built is now coming apart. This is the real legacy of America’s war in Iraq.

Thousands of Iraqis flee Mosul as militants attack. Photograph by Emrah Yorulmaz/Anadolu Agency/Getty.