When President Recep Tayyip Erdogan of Turkey accused Iran last month of trying to dominate the Middle East, there were fears his scheduled trip to the country could be in jeopardy.
His comments caused fury in Tehran, with some MPs demanding a formal apology and calling for the visit to be cancelled.
But as the main newspapers in both countries digest the visit, they all seem to agree that in the end pragmatism won the day, with both countries deciding to put politics to one side and focus on trade and business ties.
Turkey and Iran are neighbours, and the recent breakthrough in Tehran’s nuclear negotiations with the six world powers has led to hopes of a big boost to cross-border trade if a permanent deal can be reached.
Iran rolled out the red carpet for Mr Erdogan, with meetings with both President Rouhani and Supreme Leader Ayatollah Ali Khamenei.
But there was a definite subtext to the reception.
As Mr Erdogan was touching down in Tehran, a prominent Iranian newspaper, Shahrvand, went to press with a front-page cartoon portraying him as an Ottoman Don Quixote, blundering through the labyrinth of Middle Eastern politics.
President Rouhani, usually relaxed and smiling, seemed markedly formal and cold as he welcomed Mr Erdogan in the midday sunshine at Saadabad Palace in Tehran.
Mounted guards of honour holding the Turkish and Iranian flags escorted Mr Erdogan’s entourage.
Unusually they were also carrying a prominent Shia symbol: red flags bearing the name of the third Shia imam.
Observers say it was a subtle reminder to Mr Erdogan of the days of the Persian and Ottoman empires, and their long history – dating back to the 16th Century – of rivalry for regional dominance.
For many Iranians writing on social media, the red flags evoked the glory days of past great Persian leaders.
“There was no better way to remind the restorer of the Ottoman Empire of the Safavid king, Shah Abbas,” one person tweeted.
Both empires are long gone but tensions remain as Shia Iran and predominantly Sunni Turkey still find themselves on opposite sides of the fault lines dividing today’s Middle East.
Minds focused on the economy
In Syria, Iran supports the government of Bashar al-Assad while Turkey wants him gone.
Tehran and Ankara also have differences over Iraq – and in Yemen, Turkey has sided with Iran’s main regional rival, Saudi Arabia, and supported the Sunni Arab coalition, which is bombing Houthi Shia fighters. The Saudis and their allies accuse Iran of arming the Houthis, something Iran and the Houthis deny.
The two presidents, at their meeting in Tehran, discussed the situation in all three war-torn countries, but they focused – in public at least – on their common desire for the bloodshed to end as soon as possible.
It was clear that, on both sides, minds are focused on the economy.
“This is a critical phase for Iran-Turkey relations,” says Turkish commentator Sinan Ulgen, of the Edam Centre for Economics and Foreign Policy Studies.
“Once the nuclear deal is finalised and the sanctions are gradually removed, the Turkey-Iran relationship will be more important from the economic standpoint, given the huge interest of the Turkish business community in becoming more involved in Iran.”
The Iranian press has been striking a similar note.
“Thirty-billion-dollar target” was the headline in Iran’s reformist Etehad newspaper, picking up on the comments by President Rouhani that Iran and Turkey are aiming to raise bilateral trade from the current $14bn to $30bn by the end of next year.
“Cheap gas from Iran” was another key theme of the visit, according to Sharq newspaper, which quoted Mr Erdogan as saying that Turkey was ready to buy more gas from Iran, provided the price was right.
On both sides, observers seem to agree that the visit has helped to steer the Turkish-Iranian relationship back towards the right track.
The decision to go ahead with the visit, despite the controversy, has been the right one, according to Sami Kohen, of the Turkish Melliyet newspaper: “Despite the recent duel of words, [it] raises hopes that a climate that was on the verge of spoiling will improve.”