Iraqi Prime Minister Haider al-Abadi declared victory in the "liberated" city of Mosul on Sunday, his office said, in the biggest defeat yet for the Islamic State group.
Abadi "arrives in the liberated city of Mosul and congratulates the heroic fighters and the Iraqi people on the achievement of the major victory," his office said in a statement.
The announcement comes after a gruelling nearly nine-month battle to retake the northern city from the jihadists after three years under their rule.
A photo on Abadi's official Twitter account showed him dressed in a black military uniform and cap as he arrived in Mosul to announce the recapture of the city.
The fighting did not seem to be completely over yet, with gunfire still audible in Mosul and air strikes hitting the city around the time the premier's office released the statement.
The declared victory in Mosul marks an epic milestone for the Iraqi security forces, who had crumbled in the face of an IS onslaught across Iraq in 2014.
IS swept across much of Iraq's Sunni Arab heartland in a lightning offensive that year, proclaiming a self-styled "caliphate" straddling Iraq and neighbouring Syria.
But the jihadist group, which is facing twin offensives backed by a US-led coalition in both countries, has since lost large parts of the territory it once controlled.
The Iraqi forces launched their campaign to recapture Mosul in October, seizing its eastern side in January and launching the battle for its western part the next month.
But the fight grew tougher when Iraqi forces entered the densely populated Old City on the western bank of the Tigris River that divides the city.
In recent days, security forces have killed jihadists trying to escape their dwindling foothold in Mosul, as Iraqi units fought to retake the last two IS-held areas near the Tigris.
Earlier Sunday Iraq's Joint Operations Command had said it killed "30 terrorists" trying to escape across the river.
Even in the final days of the battle, thousands of civilians remained trapped inside the Old City and those who fled arrived grief-stricken after losing relatives in jihadist sniper fire and bombardments.
Around 915,000 residents have fled Mosul since the start of the battle for the city in October, the United Nations said this week.
Iraqi forces are backed by air strikes and advisers of the US-led coalition fighting IS in Iraq and Syria since 2014.
Abadi declared on Twitter late last month that "we are seeing the end of the fake (IS) state".
The recapture of Mosul will not however mark the end of the threat posed by IS, which holds territory elsewhere in Iraq and is able to carry out frequent bombings in government-held areas.
In Syria, a US-backed Kurdish-Arab alliance is fighting to oust the jihadist group from the northern city of Raqa after penetrating its heavily fortified historic centre.
The declared victory in Mosul marks an epic milestone for the Iraqi security forces, who had crumbled in the face of an IS onslaught across Iraq in 2014