No details of the pact were released but state television said the two sides had "agreed to continue cooperation in the defence arena with the creation of a national army to protect the territorial integrity and security of Iraq."
The memorandum of understanding was signed late Tuesday in Tehran where Iraqi Defence Minister Khaled al-Obaidi is holding talks with his Iranian counterpart Hossein Dahqan.
"The two sides stressed the need for consultations to ensure security, because terrorism affects not only security in Iraq but security throughout the region," the statement added.
The Iraqi military melted in the face of the jihadist surge in June, with many soldiers simply abandoning their weapons and uniforms, allowing IS to seize large areas of the country.
Within days, Shiite Iran sent military advisers to Iraq, which is also predominantly Shiite, to help train and equip troops and allied militias for a counteroffensive against IS.
Iran has also armed Kurdish forces in northern Iraq and several Iranian military personnel have been killed in Iraq and Syria, whose government Tehran also supports.
However, IS remains in control of Mosul, Iraq's second largest city, and much of the Sunni Arab heartland north and west of Baghdad.
Signup to our newsletter and follow us on Facebook and Twitter!
Iran has consistently denied having combat troops on the ground in Iraq and was never invited to join the US-led military coalition assembled against IS, dismissing allied air strikes in Iraq and Syria as ineffective.
But earlier this month the Pentagon said Iranian F-4 Phantom jets -- acquired from the United States before the 1979 Islamic revolution -- had started attacking IS fighters in eastern Iraq's Diyala province.
Tehran refused to confirm or deny the US military's report.
Diyala lies on Iran's border and Iranian officials have underlined the threat they believe that the IS advance into the province poses for its own security.
They have also said repeatedly that they will not allow any move by IS against the Shiite holy places in Iraq, including the city of Samarra, north of Baghdad, where an Iranian military adviser was killed last week.
Speaking at the funeral Monday of Revolutionary Guards Major General Hamid Taghavi, a top security official said that if IS was not tackled in Iraq, Iran itself would be targeted.
"If people like Taghavi don't give their blood in Samarra, we must shed our blood... in Shiraz, Isfahan," Supreme National Security Council secretary Ali Shamkhani said, naming two Iranian cities.
"The enemy will certainly seek to create insecurity in our country," he added.