Predominantly Shia Muslim Iran will combat the "violence and terrorism" of Sunni armed groups who have launched an anti-government offensive in neighbouring Iraq, President Hassan Rouhani has warned.

"This is an extremist, terrorist group that is acting savagely," Rouhani said live on state television.

The president did not elaborate on what steps Iran would take to help thwart a bid by fighters from the Islamic State of Iraq and the Levant (ISIL) to push towards Baghdad after seizing several cities and towns to the north.

But he said he would head to a meeting of Iran's Supreme National Security Council immediately after his speech.

That body decides on the Islamic state's major foreign policy and security policies, and it would have to approve any military support Tehran might want to provide to Baghdad.

"For our part, as the government of the Islamic Republic of Iran ... we will combat violence, extremism and terrorism in the region and the world," said an agitated Rouhani.

The president spoke even as the heavily armed ISIL on Thursday seized a string of towns near Baghdad after a lightning offensive that began in Nineveh province late on Monday.

Iran is seen as an ally of Iraq's Shia prime minister, Nouri al-Maliki, whose government's swift loss of control has raised international alarm.

On Wednesday, the Iranian foreign minister, Mohammad Javad Zarif, had condemned the "murder of Iraqi citizens" as he offered Baghdad "support" against what he called terrorism. He also did not elaborate.

ISIL is also fighting to overthrow Tehran's close ally Bashar al-Assad in Syria.

ISIL advance

ISIL continued its lightning advance on Thursday, moving into towns just an hour's drive from the capital.

The military has essentially fled, abandoning buildings and weapons to the fighters who aim to create a strict Sunni caliphate.

The advance of ISIL is the biggest threat to Iraq since US troops withdrew in 2011.

Security and police sources said Sunni armed groups now controlled parts of the small town of Udhaim, 90km north of Baghdad, after most of the army troops left their positions and withdrew towards the nearby town of Khalis.

"We are waiting for supporting troops and we are determined not to let them take control. We are afraid that terrorists are seeking to cut the main highway that links Baghdad to the north," said a police officer in Udhaim.