DUBAI (Reuters) - Iranian President Hassan Rouhani and Turkey’s President Tayyip Erdogan agreed on Wednesday to improve ties, including in the fight against terrorism, Iran’s state news agency IRNA said, following some angry exchanges between the regional rivals.

Iran's President Hassan Rouhani (R) is welcomed by Turkey's Prime Minister Tayyip Erdogan as he arrives for a meeting at Erdogan's office in Ankara June 9, 2014. REUTERS/Umit Bektas

Tehran and Ankara support opposite sides in the conflict in Syria. Largely Shi’ite Muslim Iran backs the government of President Bashar al-Assad, while Turkey, which is majority Sunni, has backed elements of the Syrian opposition.

Last month Erdogan and Turkish Foreign Minister Mevlut Cavusoglu both accused Iran of trying to destabilize Syria and Iraq and of sectarianism, prompting Tehran to summon Ankara’s ambassador.

In an apparent response to Ankara’s accusations, Rouhani was quoted by IRNA as saying on Wednesday: “Iran supports the territorial integrity of regional countries ... especially Iraq and Syria.”

“Resolving political differences (between Iran and Turkey) can lead to regional stability,” Rouhani was quoted as saying at his meeting with Erdogan, on the sidelines of an economic cooperation summit in the Pakistani capital Islamabad.

Regional rivalry between Iran and Turkey is nothing new, but political analysts have linked Ankara’s tougher rhetoric to U.S. President Donald Trump’s approach to the Middle East.

Trump has been sharply critical of Iran, including a nuclear deal it clinched in 2015 with major powers, while Turkey, a NATO ally, is hoping for improved ties with Washington after a chill caused partly by U.S. criticism of Ankara’s human rights record.

In another conciliatory move by Turkey on Wednesday, Cavusoglu told IRNA in an interview that Ankara had appreciated Tehran’s expressions of support for his government during a failed military coup against Erdogan on July 15, 2016.

“Iran was with us to support our government in every minute at that night while some other countries only called us days or even weeks after the attempted coup,” IRNA quoted him as saying.

Last week Iranian Foreign Minister Mohammad Javad Zarif had called Turkey an ungrateful neighbor.

“They (Turkey) accuse us of sectarianism but don’t remember we didn’t sleep on the night of the coup,” he said.

Despite their differences, Turkey and Iran, along with Assad ally Russia, have been sponsoring Syrian peace talks in the Kazakh capital Astana in an attempt to end the Syrian civil war, which began in 2011.