Turkish President Recep Tayyip Erdogan said he and Iranian counterpart Ebrahim Raisi agreed at a meeting on Wednesday on the need to avoid steps that could further threaten Middle East stability three months into the Gaza war.

Turkey, which supports a two-state solution to the decades-old Israeli-Palestinian conflict, has harshly criticized Israel for its attacks on Gaza, called for an immediate cease-fire, and backed legal steps for Israel to be tried for genocide.

Unlike its Western allies and some Arab nations, NATO member Turkey does not consider the Palestinian militant group Hamas, whose October 7 attack on Israel led to the retaliatory Israeli military campaign on Gaza, a terrorist group.

Iran leads what it calls the Axis of Resistance, a loose coalition that includes Hamas and armed Shiite Muslim groups around the region that have militarily confronted Israel and its Western allies. It has voiced support for Hamas.

Speaking at a news conference after meeting Raisi in Ankara, Erdogan said the two leaders had discussed ending Israel’s “inhumane” attacks on Gaza and the need to take steps for a fair and lasting peace in the region.

“We agreed on the importance of refraining from steps that will further threaten the security and stability of our region,” he said, adding the two neighbors had also agreed to continue cooperation against cross-border militant threats.

In a sign of the conflict widening, U.S. and British strikes hit Iran-backed Houthi targets in Yemen this month, in response for attacks on Red Sea shipping. Erdogan slammed the strikes as a disproportionate use of force.

Turkish Foreign Minister Hakan Fidan also said last week he had spoken to his Iranian and Pakistani counterparts after the neighbors traded cross-border fire and called for calm.

Despite its harsh rhetoric, Ankara has maintained commercial ties with Israel, prompting criticism at home and in Iran.

Raisi accused the United States of supporting what he called Israel’s crimes against Palestinians in Gaza and repeated Tehran’s appeal for Muslim countries to cut their economic and political relations with the “Zionist regime.”

“What is happening in Palestine and Gaza is a crime against humanity … and the United States and the West are supporting these crimes,” he said. “Cutting economic and political ties with this regime can certainly have an impact on the Zionist regime to end its crimes.”

Turkey and Iran have usually had complicated ties, standing at odds over a host of issues, primarily the Syrian civil war.

Ankara has backed rebels looking to oust President Bashar al-Assad and mounted several incursions into northern Syria against militants, while Tehran supports his government. Turkey has recently taken steps to improve ties with Damascus.

Raisi had twice postponed his visit, initially planned for November, over scheduling issues and attacks in the southeastern Iranian city of Kerman.

On Wednesday, the two leaders chaired a meeting of a Turkish-Iranian business council and signed various agreements.