Iraqi Prime Minister Haider al-Abadi arrived in Mosul on Sunday and congratulated the armed forces for their "victory" over Islamic State after nearly nine months of urban warfare, bringing an end to jihadist rule in the city.

Islamic State's defeat in Mosul three years after taking the city is a major blow for the radical Sunni Muslim group, which is also losing ground in its operational base in the Syrian city of Raqqa, where it has planned global attacks.

The battle for Mosul - by far the largest city to fall under the militants' control - has left large areas in ruins, killed thousands of civilians and displaced nearly one million people.

The group, however, still controls territory in Iraq and is expected to revert to more conventional insurgent tactics such as bombings as its self-proclaimed caliphate is dismantled.

"The commander in chief of the armed forces (Prime Minister) Haider al-Abadi arrived in the liberated city of Mosul and congratulated the heroic fighters and Iraqi people for the great victory," his office said in a statement.

French President Emmanuel Macron, whose country is part of an international coalition which backed the campaign with airstrikes, training and assistance on the battlefield, welcomed the defeat in Mosul of the group also known as ISIS.

"Mosul liberated from ISIS: France pays homage to all those, who alongside our troops, contributed to this victory," Macron said on his Twitter account.

Iraq still faces uncertainty and long-term stability will be possible only if the government contains ethnic and sectarian tensions which have dogged the country since the overthrow of Saddam Hussein in 2003.

The fall of Mosul exposes fractures between Arabs and Kurds over disputed territories, and between Sunnis and the Shi’ite majority.

The decaying corpses of militants lay in the narrow streets of Mosul's Old City where Islamic State staged its last stand against Iraqi forces backed by the U.S.-led coalition.

The group vowed to "fight to the death" in Mosul, but Iraqi military spokesman Brigadier General Yahya Rasool told state TV that 30 militants had been killed attempting to flee by swimming across the River Tigris that bisects the city.

Cornered in a shrinking area, the militants resorted to sending women suicide bombers among the thousands of civilians who are emerging from the battlefield wounded, malnourished and fearful, Iraqi army officers said.

The struggle has also exacted a heavy toll on Iraq's security forces.

The Iraqi government does not reveal casualty figures, but a funding request from the U.S. Department of Defense said the elite Counter Terrorism Service (CTS), which has spearheaded the fight in Mosul, had suffered 40 percent losses.

The Department of Defense has requested $1.269 billion in U.S. budget funds for 2018 to continue supporting Iraqi forces, which collapsed in the face of the few hundred militants who overran Mosul in 2014.

Backed by coalition airstrikes, an array of Iraqi forces gradually clawed back territory from Islamic State until reaching Mosul, the group's de facto capital in Iraq, last October.

It is almost exactly three years since the ultra-hardline group's leader Abu Bakr al-Baghdadi proclaimed a "caliphate" spanning Syria and Iraq from the pulpit of Mosul's medieval Grand al-Nuri mosque.

Abadi declared the end of Islamic State's "state of falsehood" a week ago, after security forces retook the mosque - although only after retreating militants blew it up.

The United Nations predicts it will cost more than $1 billion to repair basic infrastructure in Mosul. In some of the worst affected areas, almost no buildings appear to have escaped damage and Mosul's dense construction means the extent of the devastation might be underestimated, U.N. officials said.