As the man with the final word on Iran’s nuclear program, his decision and blessing would have been needed by Iran’s nuclear negotiation team for every major decision taken during last night’s negotiations with the P5+1.

The agreement was finally signed at 3 A.M. in Geneva -- which is 5:30 A.M. in Tehran. This is probably when Iran’s most powerful man could finally get some rest.

The agreement with the West is unlikely to go down well with Iran’s ultra conservatives. For years Ayatollah Khamenei, backed by his conservative supporters, advocated a policy of “resistance” over Iran’s nuclear program. This policy entailed continuing the program without conceding during nuclear negotiations. This was witnessed during the negotiation sessions between the P5+1 and Khamenei’s former top negotiator (and preferred presidential candidate) Saeed Jalili. In line with instructions from his boss the supreme leader, Jalili did not show any compromise. Instead, he emphasized Iran’s rights and how Iran had been wronged in its dealings with the West.

The pressure of sanctions meant that the supreme leader had to go against his former policy of “resistance” and adopt a new policy which was evident in the nuclear negotiations. Khamenei called his new policy “heroic flexibility.” We saw its implementation last night in Geneva.

Today, the day after the implementation of the agreement, the Iranian supreme leader would and should expect grumblings and opposition from some of his more hard-line conservative supporters, most probably behind close doors.

Such groups would argue that Iran conceded too much to the West, and that this could be interpreted as a sign of weakness by Iran’s foes abroad. “Today the West forced us to make compromises over the nuclear program, tomorrow it could be over human rights and democracy,” they could argue. In fact, many of Iran’s conservatives -- including Khamenei himself -- saw the West’s opposition to Iran’s nuclear program as an excuse to overthrow the regime.

The other concern which Iran’s conservatives will have today is that the latest Geneva nuclear deal is likely to make Rouhani very popular with the Iranian populace. And they would be right. Rouhani and his foreign minister Zarif are probably the most popular politicians in Iran today -- and will be for the next few weeks or even months. People of Iran are sick and tired of the isolation which Khamenei’s previous nuclear negotiation strategy, coupled with Ahmadinejad’s controversial outbursts such as denying the Holocaust and accusing the US of being behind 9/11 had brought upon them. Add to that Rouhani’s election promise of improving the livelihood of the people of Iran within his first 100 days in office -- a promise which he has now fulfilled. Rouhani's popularity will come at a cost of support for conservative factions and personalities in Iran.

Khamenei’s dilemma is that on the one hand he needs Rouhani, because he seems best suited and qualified to reach a deal with the West. Without a deal, the cost of sanctions could become increasingly unbearable by the regime. On the other hand, Khamenei also needs the support of the conservatives, as they have been his most loyal allies since the beginning of the revolution. Khamenei himself is a conservative and has always been one.

As important as being a conservative is to Khamenei, what is more important is to him is being a survivalist. It's no use being a conservative with no regime to rule over. Khamenei already experienced the perils of such a scenario as a young man when his anti-regime activities earned him a stint in jail, as well as being deported to the Sunni- populated city of Iran Shahr. A punishment which few Shiite clerics would welcome.

This means that for now, Khamenei is likely to try and play to both sides: giving continued credibility and support to the moderates headed by Rouhani and Jalili, in order for them to save his regime from sanctions by negotiating with the West. Meanwhile, he will also try to keep the conservatives on his side by increasing his unprecedented outbursts against Israel. Khamenei has attacked Israel before, but he never called the country a “bastard state,” as he did recently. Nor had he called any of its leaders a “rabid dog” -- a description he recently used to publicly refer to Prime Minister Benjamin Netanyahu. We are also likely to see an increase in the number of political prisoners being jailed and executed in Iran, something which the country's conservatives are likely to welcome.

The supreme leader will have a difficult balancing act to maintain over the coming months. He will have to apply the best of his skills to keep the moderates and the conservatives happy.

Ayatollah Khamenei can also count on the support of outside forces to help justify his recent strategy of “heroic flexibility.” The best and most reliable kind of support for the supreme leader has already started to arrive from Netanyahu. His description of the recent deal as a “historic mistake” is an endorsement which Iran’s supreme leader is likely to be very grateful for. When you take Khamenei’s domestic challenges into consideration, he is likely to pray for more endorsements from Jerusalem.

Meir Javedanfar is an Iranian-Israeli Middle East analyst. He teaches contemporary Iranian politics at the Interdisciplinary Center in Herzliya.
On Twitter: @meirja