Fallujah, the major Iraqi city that ISIS has held since January 2014, has officially been retaken. Iraqi army troops seized the last ISIS-controlled district in the city on Sunday, with Prime Minister Haider al-Abadi appearing on television to give a victory speech. The city that ISIS has held longer than any other in Iraq is, for the moment, out of the militant group's hands.

This is the beginning of the end for ISIS's territorial control in Iraq. After Fallujah, there's only one more urban center in ISIS's possession: Mosul, Iraq's second-largest city. ISIS's defeat in Fallujah, a longtime stronghold, reveals that it's now no longer a question of if but when Mosul falls to the Iraqi government.

But while Iraq is on the verge of ending ISIS's reign of terror, that's no longer enough. Now that the ISIS endgame is approaching, the country needs to get much better at addressing the root causes of ISIS's rise — most notably, deep sectarian tensions. These haven't gotten better over the course of the ISIS fight. In some ways, they've gotten worse.

So while ISIS's looming defeat is a cause for celebration, it's looking more and more like Iraq doesn't have a good plan for preventing it — or something like it — from rising again.

Fallujah has long been a hotbed of extremism and insurgency

Fallujah is a heavily Sunni city in Iraq's western Anbar province. For some time, the city of some 300,000 people has been the epicenter of radical Sunni Islam in the country.

"It's not, in the main, a very moderate city. It never has been, even by Iraqi standards," Douglas Ollivant, the former National Security Council director for Iraq from 2008 to 2009, tells me. It's nicknamed the "City of Mosques," and according to Ollivant, "a lot of those mosques are Saudi-funded, very extreme."

Fallujah was also a military stronghold under Saddam Hussein. "During Saddam Hussein's time, many of the town's 300,000 people had highly-paid jobs as soldiers and security officers," writes Colin Freeman in the Telegraph.

When, after the invasion, the US decided to purge Saddam's Baath party loyalists from the government and military, in a process known as de-Baathification, thousands of former Iraqi military personnel — including many in Fallujah — found themselves unemployed and more than a little angry at the Americans.

This toxic combination of Sunni extremism and virulent anti-American sentiment essentially turned Fallujah into one of the most dangerous hot spots in the post-US invasion insurgency. Fallujah became a major base for al-Qaeda in Iraq (AQI), the organization that would eventually become ISIS. The US military stormed the city twice in 2004 to try to root out insurgents, producing some of the war's most vicious fighting.

Though AQI was temporarily defeated by a US-backed Sunni uprising in 2009-'10, Fallujah's radical spirit wasn't quelled. After ISIS rose from AQI's ashes, Fallujah was the first major city it managed to seize. That was way back in January 2014, months before the group managed to sweep over a vast swath of the country's north.

Fallujah clears the way for ISIS's final defeat in Iraq

But now ISIS has been pushed out. It took about five weeks of intense fighting: Iraqi forces had to engage in firefights with ISIS fighters while simultaneously clearing out the IED land mines they had planted around the city.

Yet the outcome was, ultimately, never in doubt. Yet government-aligned forces vastly outnumbered their ISIS opponents — by roughly 20 times, per Ollivant's estimate. Moreover, they have gotten fairly skilled at taking on ISIS in urban areas, thanks in part to the training efforts of the US-led coalition.

"The Iraqi Security Forces, the uniformed ISF, don't have a problem clearing ISIS out of locations," Michael Knights of the Washington Institute for Near East Policy, told me. "It just takes longer than the Western media might like."

The fact that ISIS couldn't even defend Fallujah, a city that has long been its stronghold, illustrates just how vulnerable the group is in Iraq. ISIS's only remaining urban stronghold in the country is Mosul, Iraq's second-largest city, and Iraqi forces are already preparing an offensive on the city. It's now just a question of when, not if, Mosul is retaken — which would effectively destroy ISIS's dream of creating an actual caliphate in Iraq for the foreseeable future.

"There's really nothing big left except for Mosul," Ollivant says. "Everyone [in Iraq] understands it's just a matter of time."

This defeat in Fallujah comes in the midst of a very bad year for ISIS. Between January 2015 and mid-March 2016, ISIS lost about a quarter of its remaining territory in Iraq and Syria. The US government estimates that ISIS recruitment of fighters from abroad has dropped by at least 75 percent. Kurdish troops have moved within 35 miles of its de facto capital of Raqqa in Syria.

There are a number of reasons for this: US airstrikes have disrupted ISIS's ability to maneuver, Iraqi forces have adapted to the group's tactics, and it's simply facing too many determined enemies in Iraq and Syria to defend itself on all sides. But the conclusion, in Iraq at least, is now clear.

We're currently witnessing the death throes of ISIS's empire.

Defeating ISIS on the battlefield in Iraq is just the first step

It's not enough just to get rid of ISIS. You also have to make sure it — or something like it — doesn't come roaring back in a few years.

It's instructive, here, to look at the history of al-Qaeda in Iraq again. In 2010, the group was mostly defeated, and things in Iraq were looking up. "Iraq finally had relatively good security, a generous state budget, and positive relations among the country’s various ethnic and religious communities," Zaid al-Ali, author of The Struggle for Iraq's Future, wrote in Foreign Policy.

But this calm didn't last. By 2012, AQI had grown strong enough again to launch a series of ambitious prison raids around Iraq, liberating fighters and criminals who would later become ISIS foot soldiers. In 2013, suicide bombings were on the rise around the country, with ISIS functioning as a particularly deadly terrorist group. Right now the Iraqi government is trying to get back to 2013 — to reduce ISIS to a terrorist group rather than a territorial threat.

"The objectives of this campaign are kind of modest," Knights explains. "They're to turn us back to 2013, when things were pretty terrible on the security front. ISIS could take down a ministry building, or Abu Ghraib prison, or a provincial council headquarters."

Preventing ISIS, or something like it, from rising again isn't purely a military question

But to get all the way back to 2010, when things were relatively good, the Iraqi government will need to wage a long-term counterterrorism campaign against ISIS remnants. To prevent a replay of 2010-'14, when ISIS rose from the ashes of AQI, it will need to deal with the root cause of ISIS's rise: Iraqi sectarianism.

While the war in Syria played a significant role in ISIS's rise, its most important source of strength was the Iraqi Sunni minority's alienation from the Iraqi state. Saddam's regime, though technically secular, was predominantly Sunni. But Iraq is majority Shia, and the government has been Shia-dominated since the advent of quasi-democracy in 2003.

This sudden reversal of fortune created resentment among many of Iraq's Sunnis, who now found themselves a marginalized minority. They felt mistreated by Baghdad, and this anger helped ISIS build a support base and replenish its manpower after its near defeat.

"Raw political sectarianism in Iraq was the main causal factor [in ISIS's rise]," Fred Hof, who for part of 2012 served as the Obama administration's special adviser for the transition in Syria, explained in an email to me last year.

Thus, preventing ISIS, or something like it, from rising again isn't purely a military question. It also depends on the Shia-dominated Iraqi government's ability to actually take steps toward reconciling with the Sunnis — as well as the Sunnis' willingness to accept that a democratic Iraq means a heavily Shia government.

"Let's face it: If we don't do reconciliation, if we don't do rebuilding properly... ISIS is going to get another shot at this in two years' time," Knights tells me.

The good news is that Prime Minister Abadi is far more clear-eyed about the need to reconcile with the Sunni population than his predecessor, Nouri al-Maliki. The bad news is that Abadi's support is limited at best. Many of Abadi's legislative priorities, including reining in hard-line groups and making it easier for Sunnis to get into high levels of the Iraqi government, have stalled out.

This isn't just because of standard tensions between the Shia Maliki and Sunnis/Kurds; he's also dealing with intra-Shia political divisions. Populist cleric Muqtada al-Sadr's supporters recently staged disruptive protests in Baghdad, which were ostensibly supporting an Abadi government reform package but are really about expanding Sadr's influence. Maliki is gunning for his old job back. Shia hard-liners, backed by Iran, are blasting Abadi as soft on the Sunnis.

To make matters worse, the Iraqi government is facing bankruptcy as a result of war expenses and the collapse in oil prices.

These challenges make a push for postwar reconciliation extremely complicated. Abadi's good intentions aren't enough: He needs to overcome extraordinary political and structural barriers in Iraq in order to solve the sectarianism that could allow ISIS to rise again.

It's a challenge that makes the past year's victories over ISIS, as hard-won as they were, seem easy by comparison.