The battle has left large parts of Mosul in ruins, killed thousands of civilians and displaced nearly one million people.
“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.
The decaying corpses of militants lay in the narrow streets of the Old City where Islamic State has staged a last stand against Iraqi forces backed by a US-led coalition.
The group vowed to “fight to the death” in Mosul, but Iraqi military spokesman Brigadier General Yahya Rasool told state TV earlier on Sunday that 30 militants had been killed attempting to escape by swimming across the River Tigris that bisects the city.
Cornered in a shrinking area, the militants have resorted to sending women suicide bombers among the thousands of civilians who are emerging from the battlefield wounded, malnourished and fearful.
The battle 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 US Department of Defense said the elite Counter Terrorism Service, which has spearheaded the fight in Mosul, had suffered 40 percent losses.
The United States leads an international coalition that is backing the campaign against Islamic State in Mosul by conducting airstrikes against the militants and assisting troops on the ground.
The Department of Defense has requested $1.269 billion budget funds for 2018 to continue supporting Iraqi forces.
Without Mosul, by far the largest city to fall under militant control, Islamic State’s dominion in Iraq will be reduced to mainly rural, desert areas west and south of the city where tens of thousands of people live.
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 the 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, UN officials said.
The militants are expected to revert to insurgent tactics as they lose territory.
The fall of Mosul also exposes ethnic and sectarian fractures between Arabs and Kurds over disputed territories or between Sunnis and the Shia majority that have plagued Iraq for more than a decade.