A constellation of warring factions have seemingly set aside deadly disputes to take part in one of Iraq’s toughest challenges yet — clearing ISIS out of its last major stronghold in the country.

A successful offensive to recapture Mosul could boost desperately needed national unity, restore the pride of an army that was humiliated when it fled ISIS in 2014 and rip the heart out of the group’s self-declared caliphate.

"In a year or two we might see the next iteration of [ISIS] roll in and take over Mosul"

But the tinderbox coalition of anti-ISIS fighters that began its march on Iraq's second-largest city earlier this month, as well as the combustible mix of the city’s ethnic and sectarian groups, risks triggering yet more bloodshed even after the jihadists have gone.

"Politically it’s an opportunity, a major opportunity for us to get our politics in better shape,” said Lukman Faily, a former Iraqi ambassador to the U.S. “That can only happen if we keep focusing on this and Mosul is a good example, an acid test.”

Few doubt ISIS will eventually be dislodged from the city, but how Mosul is governed afterwards will truly determine whether the operation is a success.

A city of Sunni Arabs, Shiites, Turkomans, Assyrians, Yazidis, Christians and others, Mosul is “the most complex human terrain in all of Iraq,” according to former U.S. Gen. David Petraeus, who commanded Western forces in the country between 2007 and 2008.

“Creating the governance and prioritizing who gets the reconstruction assistance first and second, who gets basic services restored first and second, who gets the government jobs … are issues we know very well and they're very very tough ones,” Petraeus told NBC News.

Complicating the city’s liberation and eventual governance is the array of groups taking part in the offensive alongside the U.S.-backed Iraqi army, including Shiite and Sunni Arab militias, Kurdish fighters and various local tribes.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

A multitude of factions within those groups and influence from sometime rivals Turkey and Iran add yet more complexity, increasing the odds of rogue actors fighting among themselves or ignoring a government edict that only national forces and local tribal fighters enter Mosul.

Whether the Shiite-dominated government in Baghdad can control these competing groups and impose its own strategy for governance in Mosul remains to be seen, given its tenuous grip on Iraq after years of political and sectarian infighting.

Previous military operations against ISIS in mainly Sunni Arab areas of Iraq such as Fallujah and Tikrit have been hampered by disputes between anti-ISIS forces or were tainted by reports of brutal sectarian reprisals by victorious Shiite militias.

“At the moment unfortunately, there is no plan. There are many plans, many different groups have their own ideas,” said Renad Mansour, a fellow at London-based think tank Chatham House. “Again what we have in Iraq is going into a military battle, with an end in sight militarily, but no real end in sight politically.”

ISIS, which still holds territory in nearby Syria, or another Islamist outfit will likely exploit and exacerbate sectarian or ethnic squabbling over Mosul to stage a resurgence, experts say.

One of the reasons ISIS was able to take the majority Sunni Arab city so easily in 2014 were claims of abuses by the Shiite-dominated army.

“If all the people who live there don't feel that the future government represents them, then in a year or two we might see the next iteration of ISIL roll in and take over Mosul,” said Karin von Hippel, director-general of the RUSI defence think tank in London, using an alternative acronym for ISIS.

While the advance towards the city by anti-ISIS fighters has been relatively smooth so far, there are signs of difficulties to come.

Some Kurdish commanders reportedly aim to keep disputed territory they have captured during the offensive, and some Shiite militias brazenly flaunt their sectarian affiliation with chants and flags.

Related: Motley Crew of Anti-ISIS Forces Is 'Dangerous Cocktail'

But there are also reasons to be optimistic.

The army, stronger and more competent after driving ISIS out of its other Iraqi bastions, appears to be planning a long game in capturing Mosul to minimize civilian displacement and damage to infrastructure.

The quicker normal life can resume, the more likely the army will be welcomed as liberators and be able to impose its authority on a city once home to about 2 million people.

"It's a marathon, it's not a sprint. It won't take just few weeks. I think it would be longer, because we want to reduce civilians leaving and infrastructure destruction,” Faily said. “We know that those who are staying are hardened [ISIS] fighters now, so we need to make sure that the civilians are on our side and we bide our time moving forward."

Military vehicles during an anti-ISIS operation in Qayara, south of Mosul, on Wednesday. Alaa Al-Marjani / Reuters

The Kurds, who ultimately want to carve their own state out of northern Iraq, and the Baghdad government are working together militarily for the first time since 2003.

Rival Shiite militia leaders, with an eye on the recapture of Mosul, held reconciliation talks last week.

Western powers, including the U.S., France and Britain, are likely to weigh in heavily behind the Baghdad government’s claims on the city to avoid further regional instability.

Still, few doubt that chasing ISIS out of Mosul will be tough, the group’s fighters having had two years to prepare and likely ready to die fighting for the city where their leader Abu Bakr al-Baghdadi declared his caliphate.

“What you’ll be able to do will be defined by how well you take care of the civilian and humanitarian situation in Mosul,” said Jill Russell of King’s College London’s war studies department. “If they can liberate Mosul, if they can take care of the civilians who will be affected by the operation, if sectarian violence can be kept at an absolute minimum in the aftermath, then it gives a united Iraq a better chance.”