Iran is ready to assist the Iraqi government in its battle against extremist Sunni insurgents, President Hassan Rouhani has said.
He denied Iran had sent troops to fight in Iraq. However, an Iraqi source told the BBC that 130 Iranian Revolutionary Guards had entered the country to provide military training and advice.
The insurgents have seized several cities and are closing in on Baghdad.
They regard Iraq's Shia majority as "infidels".
The Islamic State in Iraq and the Levant (ISIS) is a hardline Islamist militant group that grew during the US-led occupation (2003-2011).
It is one of several jihadist militias fighting the rule of Bashar al-Assad in neighbouring Syria.
Iran has close ties with Iraq's Shia-dominated leadership under Prime Minister Nouri al-Maliki.
Iraq's Sunni minority - which was dominant until 2003 - has complained of marginalisation by Mr Maliki's government.
"If the Iraqi government asks us for help, we may provide any assistance the Iraqi nation would like us to provide in the fight against terrorism," President Rouhani said on Saturday.
"However, the engagement of Iranian forces has not been discussed. Providing help and being engaged in operations are different."
Answering a question from the BBC, he said that so far the Iraqi government had not requested help from Iran.
President Rouhani did not rule out co-operating with the United States, Iran's traditional foe, in combating ISIS: "We can think about if we see America starts confronting the terrorist groups in Iraq or elsewhere."
Analysis from Kasra Naji, BBC Persian
President Rouhani reassured Iranians that their young men would not be sent to Iraq - not yet, anyway. It is clear that his government is far from keen on putting boots on the ground in Iraq.
But at the same time, Iraq is a neighbour and a pivotal ally. Iran has been working hard in the past 10 years or so to help put in place a pro-Tehran government in Baghdad. Any threat to the status quo will be a serious blow to these efforts.
There are credible reports that the top commander of Iran's Quds Force, General Qassem Suleimani, is in Baghdad, helping to strengthen the defences of the capital and the northern holy city of Samarra, and organise and co-ordinate Iraqi Shia militia groups which are loyal to Iran.
And a source in the Iraqi province of Diyala, neighbouring Iran, has told the BBC that more than 130 members of Iran's Revolutionary Guard have entered the province with the aim of providing military training and advice. The source - who said the Revolutionary Guards did not plan to get involved in fighting - also said Iran had put two divisions of its forces on alert along the border with Iraq.
President Rouhani said he believed Iraq was capable of defending itself, but added that Iran was willing to co-operate with the US "to combat terrorism". It will not be surprising if there are contacts between the two sides already, in spite of their decades of animosity.
Iraq's most senior Shia cleric, Grand Ayatollah Ali al-Sistani, has issued a call to arms to fellow Shias.
There are reports that thousands have already joined Shia militias, which could play a crucial role in the defence of Baghdad, says the BBC's Richard Galpin who is in the city.
After taking Mosul and Tikrit earlier this week, the Sunni militants pressed south into Diyala province, which has a mixed Sunni-Shia population.
On Friday, they battled Shia fighters near Muqdadiya, just 80km (50 miles) from Baghdad's city limits.
Reinforcements from both the Iraqi army and Shia militias have arrived in the city of Samarra, where fighters loyal to ISIS are trying to enter from the north.
Iraqi Prime Minister Nouri al-Maliki visited Samarra on Saturday, insisting: "This is the beginning of the end of them [ISIS]."
US President Barack Obama has said he will take several days to decide what action to take over Iraq, but no US troops will be deployed.
In Geneva, UN human rights chief Navi Pillay warned of "summary executions and extrajudicial killings" and said the number killed in recent days might be in the hundreds.
At least 540,000 people have fled from Tikrit, Samarra and Mosul, estimates the International Organization for Migration.
ISIS in Iraq
- The Islamic State in Iraq and the Levant (ISIS) has 3,000 to 5,000 fighters, and grew out of an al-Qaeda-linked organisation in Iraq
- Joined in its offensives by other Sunni militant groups, including Saddam-era officers and soldiers, and sympathetic Sunni tribal fighters
- ISIS has exploited the standoff between the Iraqi government and the minority Sunni Arab community, which complains that Shia Prime Minister Nouri Maliki is monopolising power
- The organisation is led by Abu Bakr al-Baghdadi, an obscure figure regarded as a battlefield commander and tactician
Are you in Saadiya, Jalawla or Baghdad? Have you been affected by the latest developments? You can email firstname.lastname@example.org using the title 'Iraq'.