Standing alongside visiting Afghan leader Ashraf Ghani, Iran's President Hassan Rouhani said the tumult hitting the region meant intelligence must be shared.
His comments came after IS, which holds swathes of Syria and Iraq, said it was responsible for a suicide bombing in Afghanistan's eastern city of Jalalabad which killed 33 people.
The attack on Saturday at a state-owned bank where government workers were drawing their salaries was the first in Afghanistan claimed by IS. More than 100 people were also wounded.
Ghani's two-day visit to Iran is his first since taking over from president Hamid Karzai in September, and he was accompanied on the trip by his foreign minister and minister for oil and mines.
The Afghan leader has repeatedly raised the prospect of IS making inroads in his country, though the jihadist group has never formally acknowledged having a presence in Afghanistan.
A former finance minister and World Bank technocrat, Ghani said IS presented "a serious danger and different form of terrorism".
"People die daily, we face barbarism," he said at a joint press conference, prompting Rouhani to nod in agreement.
"And without greater cooperation a macabre phenomenon such as Daesh cannot be contained," Ghani said, using an Arabic acronym for IS.
Rouhani said: "We have agreed to cooperate further in the fight against terrorism, violence and extremism in the region, especially in border regions.
"We need intelligence sharing and, if necessary, cooperation in operations because the problems that exist are not restricted and gradually spread throughout the region, affecting everyone."
The two leaders did not specify further what they thought could be done to confront IS, which swept into Iraq from Syria last June. The group holds Mosul, Iraq's second city.
Iran has been central in the Baghdad government's fightback against IS, coordinating Shiite militias and providing military advisers from its powerful Revolutionary Guards Corps.
The largest such operation saw IS cleared early this month from Tikrit, a city north of Baghdad and the childhood home of executed Sunni dictator Saddam Hussein.
In Afghanistan, the Taliban have seen defections to IS in recent months, with some voicing their disaffection with their one-eyed supreme leader Mullah Omar who has not been seen in almost 14 years.
A person purporting to be an IS spokesman said in a call to AFP that the group was behind the Jalalabad bombing. An online post allegedly from IS made the same claim, but could not be verified.
Iran and Afghanistan have close ties. In 2001, Tehran took the rare step of cooperating with Washington in a US-led invasion that ousted the Taliban regime from power in Kabul.

Latest News from World News Desk