Iraqi PM Haider al-Abadi has visited Mosul to congratulate Iraqi forces for their "victory" over Islamic State militants in the city.
The city was "liberated", with "just one or two pockets" still controlled by IS, his office said in a statement.
Iraqi forces, backed by US-led air strikes, have been battling to retake Mosul since 17 October last year.
Islamic State militants seized it in June 2014 before proclaiming a "caliphate" straddling Iraq and Syria.
Kurdish Peshmerga fighters, Sunni Arab tribesmen and Shia militiamen have also been involved in the gruelling battle.
The Iraqi prime minister arrived to "congratulate the armed forces and the Iraqi people" on the final defeat of IS in Mosul on Sunday, the statement said.
"Victory is certain, and what remains of [IS] is surrounded, and it is just a matter of time for us to announce the great victory to our people," Mr Abadi said.
There were celebrations in the streets during Mr Abadi's visit but he has not yet given a speech formally declaring triumph.
His office says victory will be formally declared after Iraqi forces clear out the remaining pockets of jihadists desperately holding out in a tiny area near the Old City.
Airstrikes and exchanges of gunfire could still be heard on Sunday, and plumes of smoke seen rising into the sky.
The fall of Mosul does not mean the end of IS in the country. It still has territory elsewhere - such as Tal Afar and three towns in the western province of Anbar - and is able to carry out bombings in government-held areas.
At the scene - Stench of decaying corpses
Jonathan Beale, BBC defence correspondent
Troops helped a steady stream of fleeing civilians - mostly women and children - to safety. Their faces were haunted and some had to be helped.
The children didn't even flinch when there was more sound of gunfire. An older woman was so weak she could barely walk. A few babies being carried looked almost lifeless.
If this is victory it's come at a huge cost. Not just in human life. Nearly everyone rescued had had to leave dead relatives behind.
Almost every building in the old city has been scarred or completely destroyed.
Search and rescue teams are still pulling bodies from the rubble. The heat has contributed to the stench of decaying corpses.
The government announced the "liberation" of eastern Mosul in January, but the west of the city, with its narrow, winding streets, has presented a more difficult challenge.
Some 900,000 people have been displaced from the city since 2014 - about half the pre-war population - aid organisations say.
Sally Becker, an aid worker with Road to Peace, an NGO helping children get access to medical treatment in war zones, said it was the "worst devastation that I've ever seen".
"I've been working in conflict areas now for 25 years, so I've seen most of them: Bosnia, Kosovo, Chechnya, and I have never seen anything as bad as this," she said.
Save the Children warned of the psychological impact on the children "haunted by memories of extreme violence, or of loved ones killed in front of them".
"For children and their families to process these horrors and rebuild their lives, psychological support will be absolutely crucial", said Ana Locsin, Save the Children's Iraq country director.
"But right now the world is providing next to no funding for mental health."
French President Emmanuel Macron and British Defence Secretary Michael Fallon are among those to congratulate Mr Abadi, and thank soldiers - including French and British troops - for liberating the city.
In a joint statement, EU foreign affairs chief Federica Mogherini and its aid commissioner Christos Stylianides said: "The recovery of Mosul from the hands of (IS) marks a decisive step in the campaign to eliminate terrorist control in parts of Iraq and to free its people."
They called for a "process of return and the re-establishment of trust between communities".