"I announce the liberation of the city of Hawija", Iraqi Prime Minister Haider al-Abadi told a news conference in Paris.
US-backed Iraqi government troops, and Iranian-trained and armed Shiite paramilitary groups known as Popular Mobilization Units, have captured the town of Hawija and the surrounding area from Islamic State (IS, formerly ISIS/ISIL), the Iraqi military said on Thursday.
Iraqi forces "liberated the whole of the center of Hawijah and are continuing their advance", said the operation's commander, Lieutenant General Abdel Amir Yarallah.
BBC reports that Hawija, where tens of thousands of civilians live, has been under the militant group's control since 2014.
The Hawija offensive was launched in on September 21 by Iraq's army as part of its drive to dislodge the Islamic State group from the country. Iraqi security forces said IS militants were preventing some people from leaving and might have laid explosives around the town.
But he said the victory had been achieved "despite the crises that some people have tried to drag us into" - an apparent reference to the referendum on independence held by the autonomous Kurdistan Region last week despite opposition from the government in Baghdad and the worldwide community.
The UN's humanitarian affairs office (OCHA) said the number of people still in the town was unknown but could be as high 78,000.
A statement by the Norwegian Refugee Council (NRC) said that more than 12,500 people had fled and were now in need of water, food and shelter - often in overstretched refugee camps.
Hawija was one of two territories held by ISIS in Iraq.
Coupled with ongoing battles to evict the group from the Syrian cities of Raqqa and Deir al-Zour, the Islamic State is under vast military pressure and has ceded roughly 90 percent of the territory it once controlled.
ISIL has been forced out of most of the territory it seized in Iraq and Syria during a lightning offensive in the summer of 2014 that was followed by its declaration of a so-called cross-border "caliphate".