Relations between Iran and Turkey are becoming increasingly strained as they compete for influence in a changing Arab world.
The key military adviser to Iran's supreme leader told Ankara at the weekend that Turkey must reconsider its policies on Syria, the Nato missile shield and promoting Muslim secularism in the region.
Otherwise, he warned, Turkey would face trouble not only from its own people, but from its neighbours, Iran, Syria and Iraq, because it was "acting in line with the goals of America".
The characteristically undiplomatic outburst from Major-General Yahya Rahim-Safavi, an influential aide to Ayatollah Ali Khamenei, highlighted Iran's frustration that Ankara's star is rising in the Arab world while Tehran's is declining. The outcome of the contest between the region's two major non-Arab Muslim states will help shape the future of the Middle East.
Yet, experts say, Iran and Turkey have mutually beneficial relations that neither will want to see fray beyond repair.
Sir Richard Dalton, a Middle East and North Africa expert at Chatham House, a British think tank, said: "Both are keen to maintain good economic ties. Iran has long tried to keep its commercial interests largely insulated from political difficulties."
The Iranian regime watched with envy and dismay when Turkey's prime minister, Tayyip Erdogan, made a triumphal tour of North Africa last month. Before cheering crowds in Egypt, Tunisia and Libya, he extolled Turkey's successful brand of secular Muslim democracy as a template for the Arab world.
Mr Rahim-Safavi, the former commander of Iran's Revolutionary Guards, fumed that this was "unexpected and unimaginable", apparently wanting to claim that since the Egyptian people were predominantly Muslims, they would prefer a ruling system like Iran's, which places Islam firmly at its core.
The Arab uprisings have been mainly secular in nature. But Mr Khamenei has claimed they represent an "Islamic awakening" against dictatorial, Western-backed regimes, inspired by Iran's 1979 Islamic revolution. But Tehran is aware that its own model of a purportedly democratic Islamic government has little appeal in the Arab world.
Television viewers in the Middle East are well-acquainted with the Iranian regime's draconian suppression of pro-democracy protests that erupted after President Mahmoud Ahmadinejad's disputed re-election in June 2009. They are also aware that, despite its vast oil wealth, Iran is struggling to combat inflation and unemployment while Turkey's economy is booming.
Nor can Tehran promote itself in the Arab world any longer as the leading rhetorical scourge of Israel and champion of the Palestinians. Mr Erdogan has usurped that role far more convincingly.
Economic ties also are enabling Turkey to increase its soft power in Iraq, where Iran had hoped to be the main post-Saddam commercial beneficiary, because of its good political relations with Baghdad's Shiite-led government. Even so, Baghdad is supporting Iran's stance, rather than that of Turkey's, on the Syrian uprising.
Turkish pressure on Syria, Tehran's main ally in the Arab world, upsets Iran. Mr Erdogan has taken a tough and proactive stand against President Bashar Al Assad's brutal response to the seven-month-old Syrian uprising. The Turkish premier predicted recently that the Syrian leader will be ousted "sooner or later", and is set to impose its own sanctions on Damascus. Turkey is also harbouring Syrian opposition groups and army defectors.
Iran has a huge interest in Mr Al Assad's survival. His removal could sever Iran's umbilical cord to Hizbollah, Tehran's coreligionist ally in Lebanon, which gives the Islamic republic a cherished presence on Israel's northern border and enables Iran to project its power in the region.
But it is Ankara's recent decision to deploy a Nato missile early-warning system in south-eastern Turkey that has most infuriated Iran. Tehran maintains this is a US ploy to protect Israel from any counter-attack should the Jewish state target Iran's nuclear facilities.
"The missile defence shield is aimed at defending the Zionist regime," Mr Ahmadinejad declared last week, while insisting it would not "prevent the collapse" of the Jewish state.
Ankara counters that the radar system does not target a specific country and that Turkey had threatened to block the deal if Iran was explicitly named as a threat.
Mr Rahim-Safavi said trade ties with Turkey, which is an importer of Iranian gas and exports a wide range of manufactured goods to Iran, would be in jeopardy unless Ankara changes tack. "If Turkish political leaders fail to make their foreign policy and ties with Iran clear, they will run into problems," he warned in an interview with Iran's semi-official Mehr news agency on Saturday. "If, as they claim, they intend to raise the volume of contracts with Iran to $20 billion [Dh73bn], they will ultimately have to accommodate Iran."
This hard talk ignores the benefits Iran derives from its relationship with Turkey. Ankara, which has huge commercial interests in Iran, has opposed Washington's uncompromising stance on Iran's nuclear programme, arguing for a diplomatic solution to the protracted standoff instead of sanctions.
Iran and Turkey also have a common security interest in battling Kurdish rebels from each country that are based in northern Iraq. Sir Richard, a former British ambassador to Tehran, said: "Tehran and Ankara have a relationship that each regards as very important, although it's never been without its difficulties.
"Iran will try to benefit where it can with Turkey, while continuing to be frank about its opposition to some of Ankara's policies."