Iraq says its forces have driven Islamic State militants out of a key oil refinery town north of Baghdad.

The Joint Military Command spokesman, Brig. Gen. Yahya Rasool, told The Associated Press on Tuesday that army troops and paramilitary forces, made up mainly of Shiite militias, retook the town of Beiji.

State-run TV aired footage of what it said was a residential area in Beiji. Soldiers could be seen waving Iraqi flags from rooftops as thick black smoke billowed into the air.

The IS group captured Beiji and parts of a nearby oil refinery -- Iraq's largest -- during its blitz across the country's north in June 2014. The town and the refinery have been heavily contested since then.

Iraq announced that troops had recaptured the entire refinery last week.