Iran’s Supreme Leader Ayatollah Ali Khamenei is now under siege on two fronts.

Khamenei is vowing “severe revenge” against America over the killing of Iran’s most famous general, but the 80-year-old cleric is also well aware that his regime has never seemed so vulnerable to collapse at home. He knows that his next step — against the world’s foremost military superpower — will be onto the thinnest of tightropes.

In the short term, he has no choice but to vow retaliation. Qassem Soleimani was a near-legendary figure in Iran, who gained international fame for his victories against the Islamic State in Iraq and Syria. He died in a U.S. airstrike while leaving Baghdad airport, and the Pentagon said he was planning attacks on American diplomats and troops.

Khamenei immediately declared three days of national mourning for Soleimani and pledged to retaliate against “the criminals who stained their impure hands with his blood.”

Soleimani was a lionized folk hero to many units of the Revolutionary Guard that keep Khamenei in power, and his protégés will doubtless be ravening to strike back at targets across the world, particularly in their strongholds across the Middle East and Persian Gulf.

The big unknown for Khamenei — and frankly for everyone — is to what extent most Iranians would back their leader in a regional showdown.

But "blood vengeance" — as Khamenei puts it — is a high-risk gamble.

Iran’s leader has to weigh up the dangers of a protracted struggle when outright opposition to the Islamic Republic has never run so high at home. In November, the country erupted into unusually broad-based protests that the authorities crushed with an iron fist, killing hundreds of demonstrators and imprisoning thousands. A sharp reduction in fuel subsidies proved to be an explosive flashpoint for broader fury over corruption, state mismanagement and the country’s repression of civil liberties. With oil income pinched by sanctions and U.S. President Donald Trump's strategy of "maximum pressure," the economy is showing signs of nearing breaking point and welfare schemes are becoming unaffordable.

While Soleimani enjoyed peculiarly deep personal veneration across Iran and his military pedigree dated back to the war with Iraq in the 1980s, that doesn’t buy the leadership wide affection for its repressive police state and security apparatus. The Revolutionary Guards are often viewed by many ordinary Iranians as a leading part of their country’s malaise. The guards are not only used as shock troops willing to open fire on protesters, but are also seen as the epitome of the country’s cronyism and rampant corruption.

The big unknown for Khamenei — and frankly for everyone — is to what extent most Iranians would back their leader in a regional showdown sparked by a revenge strike for Soleimani. Patriotism runs deep in Iran, but in recent years protesters have also become far more cynical about Tehran’s foreign adventurism when the domestic economy is creaking. Their fundamental questions are about why there is money for escapades in Iraq, but not for them.

Regime change

The Iranian regime's concerns about the fragility of its own survival have increasingly bubbled to the surface since November’s protests. In late December, Khamenei took to Twitter for a surreal public musing on why Iran was not about to suffer the same fate as the Soviet Union. The mechanisms of regime collapse are clearly preying on the mind of Iran’s elite.

As far as Khamenei was concerned, the biggest difference between the USSR and Iran was that Moscow had no popular support. “Their leadership could never count on the people,” he concluded, seemingly without the least shred of irony about the brutal crackdown that he had just unleashed on his own people. In the narrative about the protests peddled by state propaganda, Khamenei is willing to admit people have “rightful” economic demands but he insists he had to send in the troops because protests were hijacked by Iran’s foreign enemies, who were plotting “a dangerous conspiracy.”

Not many people are buying the argument that it was foreign enemies who pushed Iranians to break one of the country's ultimate taboos by chanting "Death to Khamenei" in the streets.

Even in his own religious camp, there are many who fear Khamenei has not realized that the whole edifice of the state could be about to crumble. BBC Persian reported on Thursday that 100 conservative activists had taken the extremely rare step of writing to Khamenei to demand major structural reforms to avoid wider demonstrations, the “collapse of the regime” and the overthrow of “religious rule.”

Indeed, there are several respects in which a moribund Iran now looks far closer to the fraying Soviet Union — both in terms of its destabilizing oligarchy and its growing ethnic unrest — than Khamenei would like to admit.

For many Iranians, any ideological belief in the revolution burned out years ago, and the system is now based on venal networks of graft and patronage. Many of the elites in the Revolutionary Guards and in opaque state financial foundations, the bonyads, have their paws in honey pots such as mines, oil fields, engineering enterprises, fuel-smuggling and drug-running. Like the USSR, Iran has created a cadre of oligarchs, whose loyalty is based on money, not ideology.

To Khamenei, the obvious danger is that the strategic priority of these oligarchs could now well be to save their own assets and money-making rackets, rather than protect his clerical rule. To confront this risk of such corruption, which he calls Iran's “seven-headed dragon," he has appointed hard-line judiciary chief Ebrahim Raisi, widely tipped as his potential successor, to lead an anti-graft purge.

Iran's other similarity to the demise of the Soviet Union, which is severely alarming Iranian security services, is the heightened potential for separatist, ethnic conflict.

But this looks like too little, too late. Corruption is no longer a small parasite feeding on the state, but has completely taken over the host. The eye-watering scale of the graft has delivered a coup de grâce to the regime’s popular support. It is now a weary cliché for Iranians to complain their gas-and-oil-rich country is kheili servatmand — ever so wealthy — but that the cash is all creamed off. With a grin, many will twirl a finger over their heads to denote a turban — a charades-like code meaning that all the money is funneled to the mullahs.

Iran's other similarity to the demise of the Soviet Union, which is severely alarming Iranian security services, is the heightened potential for separatist, ethnic conflict. Among Middle Eastern countries, Iran was long seen as among the most coherent nation states. Relations with Kurdish and Arab minorities in the west were often tense but seemed manageable. That narrative looks far less certain now after ferocious showdowns during November’s protests, and a particularly bloody response from Iranian forces, including a massacre near the southwestern city of Mahshahr, where many people are Arabs.

Ramping up the repression

In the meantime, it is already clear that Tehran’s response to the growing disaffection at home will be to double down on repression. A demonstration planned for late December was snuffed out before it could even get going, with a massive roll-out of security forces. Expect more internet blackouts, arrests and live rounds.

Parliamentary elections on February 21 — highly unlikely to be free and fair — will also be a prime opportunity for Khamenei’s allies to lay down a marker of hardline intent by mobilizing a voter army among the units of the basij militia.

But yet another rigged election will only be a red rag to a furious public.

It is important not to understate the importance of the fuel price hikes announced in November. For years, Iranians have been incensed by restrictions of their freedoms, high unemployment and water shortages, but the regime has used fuel subsidies and other welfare schemes to (just about) keep the lid in the pressure cooker. Now that oil exports have reduced to a trickle because of sanctions, subsidies have to be slashed, and the most basic economic contract between the rulers and the ruled has been broken.

This is why the ruling clerics know they are facing the fight of their lives. They have promised a generous budget this year with welfare perks to counterbalance pricier fuel, but the numbers defy economic gravity unless there is a dramatic increase in Iran’s oil income. In the meantime, the more expensive fuel is pushing up the price of basic household goods.

In such a combustible environment across the nation, from Tabriz to Zahedan, Khamenei will have to calibrate his promised revenge very cautiously.

He insisted that Soleimani's blood had been shed by "the most barbaric of men." But he will also be deeply worried about how many of his own people would use the same language about him.