The leaders of Shiite Iran and Sunni Qatar vowed Sunday to cooperate to fight "terrorism in the region," President Hassan Rouhani's office reported as Iraqi forces counter a militant onslaught.

The pledge to play a "constructive role to establish security and stability" came in a phone call between Qatari Emir Sheikh Tamim bin Hamad al-Thani and Rouhani, a statement from the Iranian president's office said.

Rouhani said that in order to defeat "the hurdle of terrorism and extremism all Muslims should come hand in hand and cooperate," it said.

Iran is ready, he said, to do just that and "fight security problems and instability in the region" that benefit only "Zionists and the enemies of the Muslim world."

He did not elaborate.

Predominantly Shiite Iran has vowed to support ally Baghdad against the Sunni insurgency led by the Islamic State of Iraq and the Levant (ISIL), whose fighters have overrun swathes of five Iraqi provinces since launching an offensive in early June.

Iranian leaders insist the Iraq crisis is not sectarian but a fight against terrorism. Iranian media, however, have accused Qatar and Saudi Arabia of supporting the jihadist Sunni fighters.

Without naming anyone, Rouhani himself warned on June 22 that Muslim states which funnel petrodollars to "these savage terrorists" of ISIL would become their next target.

Sunday's statement said the Qatari emir noted "the necessity for cooperation between Muslim nations to prevent the further spread of (the Iraqi) crisis in the region."

"We should all cooperate together against terrorism in the region because the current crisis is very dangerous," he said.

Qatar's emir and Iran's president spoke as thousands of Iraqi troops counter-attacked against the militant-held city of Tikrit.