Iranian Ayatollah Ali Khamenei, center, arrives at a graduation ceremony of a group of the Revolutionary Guard students in Tehran on May 10. (European Pressphoto Agency)

Mehdi Khalaji, a Qom-trained Shiite theologian, is a fellow at the Washington Institute for Near East Policy.

Now that Iran has gone to the ballot to elect a president, U.S. policymakers should turn their attention to a more important transition in the offing. Ayatollah Ali Khamenei, the 77-year-old supreme leader, is in poor health, and he could die at any time. When he does, a new generation of the Islamic republic’s elite will have to decide upon his successor — a process almost certain to be highly contentious.

Iranian elections are part of an impressive mechanism of social control. Unlike the shah’s regime, the Islamic republic’s elite knows exactly how revolutions start and what keeps them going. Building on first-hand experience, as well as the experience of 21st-century totalitarian regimes, the government in Tehran has designed a sophisticated system for destroying traditional social bonds, isolating citizens from each other and raising the cost of any public action that might undermine the regime.

This system of social control has grown even more efficient as recent developments in the Middle East have intensified Iranians’ security and economic concerns to the point where they overshadow the desire for democracy. The Islamic State, for one, has been portrayed in Iran as a brutal entity backed by western powers against Tehran and its regional allies. Meanwhile, Iranians worry that a popular uprising could result in the same sort of grim outcome experienced by so many of the countries of the Arab Spring. They fear the same sort of backlash as in Egypt, where the old guard returned to power in a counter-revolutionary coup and reinstated the old repressive apparatus with a vengeance, or as in Syria, in which hundreds of thousands die in a civil war. Such anxieties overshadow the lack of democracy and the regime’s record of abuse of human rights.

Hassan Rouhani’s victory in the 2013 presidential election marked a new approach by the urban middle class, which sought modest change through the mechanism offered by the regime, namely elections. For this segment of society, elections are the only way to prevent the situation from getting worse — even if these voters are all too aware that the electoral procedure is tightly controlled by the government.

The regime suffers from ideological bankruptcy, and so it is relying increasingly on the military, the security services and the intelligence agencies. The mixture of ideological failure and intensified hard power had produced a somewhat paradoxical collective mood. Even if they don’t love the regime, many people see it as the only reliable guarantee against the uncertainties of a turbulent region.

At the same time, ordinary people enjoy considerable freedom in their private lives thanks to the widespread black market and cultural underground. Just about any banned service or good can be found. Owning a satellite TV receiver is legally banned, for example, but more than half of the population of 75 million, including clerics and religious citizens, watch satellite broadcasts in their homes. Normal life is possible, and its distractions leave people with little desire for regime change.

Even so, the fragility of the political system reveals itself at times of crisis. The 2009 massive public protests were a complete surprise. The most critical moment in the history of Iran will occur when Khamenei leaves the scene. Since 1989, when his predecessor, Ayatollah Ruhollah Khomeini, died, society has lost its faith in ideological values. At the same time, the ruling regime has become a huge bureaucracy with overlapping institutions, meaning it will be impossible for a small number of top officials to quickly appoint a successor in secret. During his rule, Khamenei has shaped the Islamic republic according to the principle of divide and rule. By creating many parallel institutions with similar mandates, he has prevented any one of them from holding full authority in a particular sphere. This ensures that he remains the ultimate arbiter of power.

The post-Khamenei period will probably develop according to two scenarios. In one, the powerful Islamic Revolutionary Guard Corps will take the lead in determining his successor. The guard’s internal factions, who are unknown to the public at large, will manage to form a rough consensus about who should be the next supreme leader. In the other, the guard factions fail to reach an agreement, in which case they will presumably begin to fight each other publicly. The result could be chaos that paralyzes the government’s ability to make key decisions.

Western countries should understand that a post-Khamenei regime will not necessarily be easier to deal with. Yet the key principles remain the same. While the West should maintain engagement with Iran, it should do so in ways that allow it to maintain pressure on the regime. No matter who is in charge after Khamenei, Iran will not be willing to negotiate seriously unless the United States and its allies show that threatening their interests comes at a price.