Dressed in a black uniform, similar to the type worn by Iraqi special forces, he arrived at the city’s airfield and greeted army officers.
Mr Abadi’s office said: “The commander in chief of the armed forces Haider al Abadi arrived in the liberated city of Mosul and congratulated the heroic fighters and Iraqi people for the great victory.”
However, there has not yet been an official statement that the entire city – the second biggest in Iraq – has been retaken.
IS still holds less than one square kilometre of the city and is using human shields, suicide bombers and snipers to cling on to the territory. The militants have pledged to fight to the death.
Some of their fighters have been trying to swim across the River Tigris, which bisects Mosul.
Iraq’s Joint Operations Command said 30 people were shot and killed while attempting the crossing.
Soldiers have been celebrating the “liberation” by dancing on tanks to patriotic music and re-raising the Iraqi flag.
The declared victory in Mosul marks an epic milestone for security forces, who crumbled in days in the face of an IS onslaught across Iraq in 2014.
They have been supported by a US-led coalition.
Around 915,000 residents are estimated to have fled the city – which has been the terror group’s de facto capital in Iraq – since the latest offensive began in October.
The terror group still controls strategic pockets in Iraq, and is able to carry out bombings in government-held areas.
Defence Secretary Sir Michael Fallon hailed the development against IS in “a city that was ground zero for their so-called caliphate”.
He said in a statement: “I congratulate Prime Minister Abadi, and the Iraqi forces who have been fighting on the ground with great bravery and care against a brutal opponent.
“Daesh has total disregard for innocent civilian life and we should welcome their defeat in a city that was ground zero for their so-called caliphate.
Sir Michael also hailed Britain’s role in the conflict, but warned: “While these pinpoint strikes have brought an end to Daesh in the city, there is still more to do.
“This barbaric group remains dug in west of the Euphrates and clearing operations in and around Mosul will be needed because of the threat from improvised explosive devices.”
:: October 17, 2016– Iraqi forces launch battle to retake Mosul
:: November 1 – Army enters the city for the first time since 2014
:: November 23 – Shia-dominated paramilitary units say they have cut IS supply lines between Mosul and Raqqa
:: January 24, 2017 – East Mosul is “fully liberated”
:: February 19 – Mr Abadi announces start of battle for west Mosul
:: March 14 – Iraqi forces capture several symbolic sites
:: June 21 – IS blows up city’s iconic leaning minaret
:: July 9 – Mr Abadi declares victory in ‘”liberated” Mosul