Alarmed by signs that president Bashar Al Assad could well lose power, Iran is scrambling to retain influence in Syria, its staunchest Arab ally through three often turbulent decades.
That could be a mission impossible.
Associated with Mr Al Assad's bloody crackdown against Syrian rebels, distrusted by opposition groups and sanctioned by the West over its nuclear programme, Iran has little room to manoeuvre.
The collapse of the Assad dynasty could threaten Iran's links with Hizbollah, Tehran's Shiite ally in Lebanon, which gives the Islamic republic a proxy presence on Israel's northern border and enables Iran to project its reach into a predominantly Sunni Arab world.
Mr Al Assad's removal from power could also tilt the regional balance of power in favour of Saudi Arabia, Iran's main Arabian Gulf rival which, along with Qatar, has been funding the Syrian revolutionaries.
Iran's support of Mr Al Assad has damaged its attempts to nurture relationships with newly elected Islamist governments in the region. Tehran is particularly keen to mend a long-standing rift with Egypt.
Tehran's public relations spin on events in Syria is that all is well - it described the situation as "calm" on Sunday - despite a day of heavy fighting in Damascus and Aleppo.
"But the signals are that the regime is worried and divided over its response," said Scott Lucas, an Iran expert at Birmingham University in England. "The office of the supreme leader, Ayatollah Ali Khamenei, is setting out a hard line while the foreign ministry is taking a softer approach."
Belatedly, Tehran appears to be mulling a backup plan should Mr Al Assad be ousted. The country's foreign minister, Ali Akbar Salehi, said last week that Iran was ready to sit down with the Syrian opposition and host talks with the Syrian government to help broker a democratic transition.
Syria's opposition swiftly rejected the offer, which came amid a rare public debate in Iran over the wisdom of having unswervingly supported the Assad regime, at any cost, throughout the 17-month uprising.
Iranian pragmatists had long called for a more balanced approach so that Tehran could hedge its strategic bets, while moderates were reluctant to undermine Iran's initially enthusiastic endorsement of the Arab Spring uprisings.
Those fears were echoed more recently by conservative figures in the Iranian regime.
"The whole world is against Syria and we are here defending Syria, a country accused of crimes against humanity," said Mohammad Ali Sobhani, a diplomat who formerly served as Iran's ambassador to Lebanon and Jordan.
"We are not playing the game very well," he told the semi-official Khabaronlinewebsite this month. But regime hardliners had insisted on giving Mr Al Assad their full support. They were convinced Tehran's western adversaries, along with its Arab rivals and the "Zionist regime" were hoping to break the "axis of resistance" linking Iran, Syria and Hizbollah against Israel and the US.
Iran had also calculated Mr Al Assad would crush the uprising, as Iran had violently snuffed out the huge street protests ignited by president Mahmoud Ahmadinejad's disputed re-election in 2009.
Iran's main but forlorn hope is to be included in international negotiations on the transition to a post-Al Assad Syria where it could protect its interests while portraying itself as an indispensable regional power broker.
Russia and Kofi Annan, the former UN secretary general turned joint UN and Arab League peace envoy to Syria, argue Iran could be "part of the solution". But the US is adamant Iran will play no diplomatic role, branding it "part of the problem".
Iran's "one-track" policy of support for Mr Al Assad had cost it a seat at the table, said Farideh Farhi, an Iran expert at the University of Hawaii.
"If Iran's only leverage in Syria is through Assad and company, what can Iran contribute beyond what Russia is already doing - or not doing?" Ms Farhi added.
Iran yesterday proposed again that Syria hold presidential elections as a way to end the civil war.
That plan was certain to be rejected by the Syrian opposition and would be nearly impossible to stage under the current level of violence. But it suggested that Tehran recognises the growing pressures on Mr Al Assad's regime and is seeking a way to preserve a pro-Iranian leadership in Damascus.
Sir Richard Dalton, a British former ambassador to Tehran, said: "Iran wants stability restored to Syria. They used to believe Assad offered the best chance of that, but doubts are creeping in and they won't stay loyal to a losing Assad forever."
Sir Richard, an associate at Chatham House, a London think tank, added: "I don't think Iran will be despairing if Assad goes."
Primarily, Iran wants Syria to remain a bridgehead for Iranian military support to Hizbollah, and maintain lucrative commercial ties between Tehran and Damascus. But unlike its sponsors in Tehran, and with fewer options, Hizbollah has refused to hedge its bets on Syria.
On the face of it, Tehran and Damascus make unlikely bedfellows. Non-Arab Iran is a hardline Shiite Islamic republic. Syria is a staunchly secular Arab state where the majority of the population is Sunni, although Mr Al Assad's family and the bedrock of his regime are from the minority Alawite sect, an offshoot of Shiite Islam.
The Iranian-Syrian alliance is one of convenience, but it has been remarkably enduring, based on making common cause against mutual enemies, primarily Saddam Hussein's Iraq and Israel.
Its days, however, now seem numbered.