The Syrian war went through one of its bloodiest stretches in recent weeks, with Iranian proxies battling Turkish-backed rebels for control of the city of Aleppo. At the same time, Iran’s foreign minister visited Ankara for the second time in two months for talks on how to improve bilateral ties, boost mutual trade, and bolster energy cooperation.

This rapprochement between Sunni-majority Turkey and Iran’s Shiite theocracy, which began earlier this year and picked up pace after the failed July coup against Turkish President Recep Tayyip Erdogan, defies the easy characterizations of the region’s mayhem as a sectarian conflict.

It also shows the ability of these two regional powers to compartmentalize their differences over the future of Syria—and to focus on areas where they share a common agenda.

These overtures, unsurprisingly, have caused unease among the countries that used to think of Turkey as an ally—in the West and even more so among the Sunni Arab states that consider Iran an existential enemy.

“Turkey is in a balancing game, trying to mend fences with everyone around it. But one would expect Turkey to be more understanding of Saudi Arabia and the rest of the Gulf in their stance against Iranian expansion in the area,” said Abdulhaleq Abdulla, a political scientist in the United Arab Emirates.