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.
Reached by telephone in Beiji, 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, Gen 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 locality they have recaptured to date.
The two officials said fierce battles were fought early today around the refinery and that government warplanes strafed 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.