Iraqi government forces have driven Islamic State militants out from their remaining strongholds inside the oil refinery town of Beiji.
Officials said it is a key victory over the terror group that has captured much of northern and western Iraq in a summer offensive.
The Iraqi troops, backed by allied Sunni militiamen, also lifted the Islamic State group's siege of the oil refinery, Iraq's largest, and hoisted Iraq's red, white and black flags atop the sprawling complex hosting the facility.
The officials said the army used loudspeakers to warn the small number of residents still holed up in the town to stay indoors while bomb squads detonated booby-trapped houses and remaining bombs planted on the roads.
State Iraqi television also reported the "liberation of Beiji", quoting the top army commander there, General Abdul-Wahab al-Saadi.
Islamic State extremists captured Beiji during their summer offensive. The Iraqi forces had collapsed in the face of that onslaught but have since partially regrouped and went on the offensive, with Beiji the biggest area they have recaptured to date.
Since August, the Iraqi military has been aided by air strikes from a US-led coalition targeting Islamic State positions in Iraq and in neighbouring Syria.
The two officials said fierce battles were fought early on Friday around the refinery and that government warplanes hit Islamic State positions around the facility on the northern edge of the town. The refinery's capacity of some 320,000 barrels a day accounts for a quarter of Iraq's refining capacity.
Beiji will now likely be a base for staging a push to take back Saddam Hussein's home town of Tikrit to the south.
Government forces tried to retake Tikrit earlier this year, but their campaign stalled and the city remains in Islamic State hands.