Iran is to help Iraq rebuild its army under an agreement that could formalize Tehran's military support for its neighbor, which remains under assault by the Islamic State of Iraq and Syria (ISIS) group.
No details of the pact were released but state television said the two sides had "agreed to continue cooperation in the defense 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 Defense 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 ISIS 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 ISIS.
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, ISIS remains in control of Mosul, Iraq's second largest city, and much of the Sunni Arab heartland north and west of Baghdad.
Iran has consistently denied having combat troops on the ground in Iraq and was never invited to join the U.S.-led military coalition assembled against ISIS, 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 ISIS fighters in eastern Iraq's Diyala province.
Tehran refused to confirm or deny the U.S. military's report.
Diyala lies on Iran's border and Iranian officials have underlined the threat they believe that the ISIS advance into the province poses for its own security.
They have also said repeatedly that they will not allow any move by ISIS 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 ISIS 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.