FILE - This image posted on a militant news Twitter account on Thursday, June 12, 2014 shows militants from the al-Qaida-inspired Islamic State of Iraq and the Levant (ISIL) removing part of the soil barrier on the Iraq-Syria borders and moving through it. (AP Photo)
Iran warned on Sunday that "any foreign military intervention in Iraq" would only complicate the crisis, after the US said it was deploying a warship in the Gulf.
"Iraq has the capacity and necessary preparations for the fight against terrorism and extremism," foreign ministry spokesman Marzieh Afkham was Sunday quoted as saying by the ISNA news agency.
"Any action that complicates the situation in Iraq is not in the interests of the country nor of the region," Afkham said, adding, "The people and government of Iraq will be able to neutralise this conspiracy."
Iraq is battling an offensive by Sunni militants who have advanced to within 80 kilometres (50 miles) of Baghdad's city limits after seizing a swathe of the country's north.
Responding to the crisis, the Pentagon said on Saturday the United States had ordered an aircraft carrier, the USS George H.W. Bush, into the Gulf.
Afkham's comments come a day after President Hassan Rouhani said he believed the Iraqis have the capacity to "repel terrorism" and that Iran had not been asked for help by its neighbour.
But in surprise comments he added that Iran may consider cooperating with its arch-foe the United States to fight the Sunni extremist militants in Iraq.
"If we see that the United States takes action against terrorist groups in Iraq, then one can think about it," he said, despite the lack of diplomatic relations between Tehran and Washington for more than three decades.
"We have said that all countries must unite in combating terrorism. But right now regarding Iraq... we have not seen the Americans taking a decision," Rouhani added.
The deployment of the aircraft carrier was ordered by US Defence Secretary Chuck Hagel and comes amid calls for air strikes to blunt the insurgents' lightning offensive that caught Iraq's security forces on the hop, with many soldiers throwing away their uniforms and fleeing.
However, Iraqi troops launched a counter-offensive on Saturday, recapturing two towns north of Baghdad, while thousands of volunteers answered a call to arms from top Shiite cleric Grand Ayatollah Ali al-Sistani.