Iran will attack Islamic State group jihadists inside Iraq if they advance near the border, ground forces commander General Ahmad Reza Pourdestana said in comments published on Saturday.
"If the terrorist group (IS) come near our borders, we will attack deep into Iraqi territory and we will not allow it to approach our border," the official IRNA news agency quoted Pourdestana as saying.
The Sunni extremists of IS control a swathe of territory north of Baghdad, including in Diyala province, which borders Shiite Iran.
Signup to our newsletter and follow us on Facebook and Twitter!
The United States launched air strikes on IS targets in Iraq in August and has since widened them to Syria, where the jihadist group has its headquarters, as part of an international coalition to crush the group.
Iran is a close ally of the Shiite-led government in Iraq and has been unusually accepting of US military action in Iraq against the jihadists.
It has provided support to both the Iraqi government and Iraqi Kurdish forces fighting the jihadists and has dispatched weapons and military advisers.
But Tehran, a close ally of the Damascus government, has criticised air strikes on Syria, saying they would not help restore stability in the region.
Iran's supreme leader Ayatollah Ali Khamenei has said he rejected a US offer to join the international coalition it has been building against the jihadists.