On Friday, Iran will elect its next president. More than 1,600 people registered as candidates, but only six were approved by the 12-member Guardian Council, the appointed religious authorities. The front-runners are Ebrahim Raisi, Iran’s hard-line former attorney general who now runs the country’s holiest site, and Hassan Rouhani, the popular moderate incumbent. Just like in the United States, these quadrennial contests often pit conservatives against progressives, or their theological equivalents.

But no matter who wins, one thing is almost certainly true: The president will have a grueling experience working with the supreme leader, Ayatollah Ali Khamenei. The election is only the first, fleeting battle. The next one unfolds slowly, often in secret, and cannot really be won. In every case, it has ended with bitterness, resentment and mutual distrust between the country’s two most powerful men.

A presidential election is the most obvious challenge to Khamenei’s authority. It is the one time when the people of Iran can voice, in unison, their opinion about the direction the country should take. An Iranian president, as an elective officeholder, has to win popular support — he is the people’s choice. While the supreme leader can exercise final say on all state matters, he is not an avatar of popular sovereignty, an asymmetry he faces with every president.

Khamenei himself served as Iran’s president in the 1980s, before the Assembly of Experts, a group of more than 80 clerics tasked with choosing and supervising the supreme leader, elevated him to the ultimate position after the death of Ruhollah Khomeini, the system’s founder. So he understands what power the president wields. Since then, he and successor presidents have developed a sometimes cooperative approach. “The supreme leader might have the ultimate say on all major decisions,” says Mehrzad Boroujerdi, a political scientist at Syracuse University. “But he’s not a leviathan that everyone obeys without question.” His office, with its unchecked executive power and control of the armed forces, was designed to maintain revolutionary principles, while the presidency could be geared toward the pragmatic work of managing and developing the country.

But just as often, the roles are at odds. In the early years of Khamenei’s leadership, information was disseminated only through state-controlled channels, which portrayed the Islamic establishment as wholly unified. Now, much greater and faster access to unfettered information is available nationwide, despite official bans, and ordinary citizens are far more aware of the fissures that exist in public opinion and government. When a president’s successes became more measurable, so did his perceived threat to Khamenei’s standing.

This dynamic has played out repeatedly. Mohammad Khatami, who was elected with nearly 70 percent of the vote in 1997, ushered in social reforms within the system’s rules and regulations, always respecting Khamenei’s authority. In turn the leader initially supported Khatami. But as the first term ended, Khamenei ratcheted up his criticism of the president’s policy of expanded social freedoms, which were deemed by hard-liners as anti-revolutionary. Khamenei calls reform a “change in attitude,” away from his idea of true Islam.

Khatami won reelection in a 2001 landslide, but Khamenei delayed his inauguration over disputes between their political factions. Then, years after the president left office, Iran’s conservative judiciary banned state media from sh owing images of, or even mentioning, Khatami, arguably the most revered figure in the regime’s history. Because of the widespread use of social media in Iran, however, Khatami is still a key voice in Iranian politics; he threw his weight behind Rouhani again this year.

Mahmoud Ahmadinejad came next. He won his first term in 2005, offering a platform that sounded more like the Iranian traditionalism the supreme leader is known for. Then, in 2011, Ahmadinejad tried to increase his own presidential powers when he forced Iran’s intelligence minister to resign, a move that Khamenei did not approve. A two-week standoff ended when Ahmadinejad acquiesced to the minister’s reinstatement. After that, Khamenei distanced himself from the president. Figures close to the supreme leader began referring to Ahmadinejad’s inner circle as a “deviant current” that was attempting to undermine clerical rule. The moniker stuck, and although the president never faced criminal charges, several of his cabinet members ended up in prison.

Rouhani’s victory in the 2013 election — winning more than half the vote in a field of six candidates — was widely considered a rebuke of Khamenei-championed policies that led to years of international isolation and economic sanctions. Rouhani’s nuclear deal, struck with President Barack Obama, lifted those measures; it is the single biggest diplomatic achievement in the nearly four-decade history of the Islamic Republic. Now Rouhani is focused on expanding civil liberties, calling for freedom of expression and an end to political arrests. Khamenei has yet to intervene, and relations are still relatively cordial, but the pattern suggests it is only a matter of time until they fray.

“If the past is any indication, some level of disagreement should be expected,” says Mohsen Milani, executive director of the Center for Strategic & Diplomatic Studies at the University of South Florida. He suggests areas of possible friction in how Iran should respond to President Trump, an Arab alliance or Iran’s role in supporting Syrian President Bashar al-Assad.

Raisi, Rouhani’s opponent, is a conservative protege of Khamenei. Yet a victory for the conservative in Friday’s election would not exempt him from the forces that, over the long run, would strain his relations with the supreme leader, just as they hurt Ahmadinejad’s.

Even Khamenei’s closest alliance could not withstand the pressures that drive the country’s leaders into conflict. After he became leader, his close friend Ali Akbar Hashemi Rafsanjani won election as president, an office he held from 1989 to 1997. Rafsanjani had been integral in having his friend Khamenei named supreme leader. This was a tumultuous time. The eight-year war with Iraq, which saw the deaths of hundreds of thousands of Iranians, had just ended, and the two men worked to rebuild the country.

It was a rare period of political unity, but it would not last. The two men began to see the country’s future differently: Rafsanjani supported efforts to mend relations with the West and develop Iran’s economy — positions he espoused until his death this year. But Khamenei wanted Iran to be a powerful force among Islamic nations, a counterweight to the Persian Gulf Arab kingdoms. “The debate that started in the 1990s between Khamenei and Rafsanjani still continues today,” says Syracuse’s Boroujerdi.

Rafsanjani and Khatami were key players in the regime’s most public rift to date, when Rafsanjani called for an investigation into alleged voter fraud that led to Ahmadinejad’s second term. Khamenei, in what was seen at the time as a rebuke of his old friend, said that Ahmadinejad’s “views are closer to mine” than Rafsanjani’s.

Evidence of Khamenei’s attitude lies in a constitutional provision that allows former presidents to run for a third term after at least one out of office. As he gets older, Khamenei and the clerical bodies that support him see the prospect of a returning president as unacceptable. In 2013 and again this year, two of the three former presidents, Rafsanjani and Ahmadinejad, were formally blocked from entering the race. In a meeting last August, according to leaked reports, Khamenei told Ahmadinejad, “Your presence in the election will polarize it, and this is not in the interest of the revolution and the people.” Two-term presidents project the image of stability. Three-term presidents start to look a lot like an attempt to displace Khamenei as a permanent pillar of the nation.

At the core of Khamenei’s struggle with his presidents is the question of the Islamic republic’s future. Will it stick to its ideological roots and remain insular and disconnected from the world in fundamental ways? Or will it open to international relations, increasing trade and allowing for greater personal freedoms for its citizens? The latter is seemingly the will of Iran’s people, who, when they turn out to vote in local and national elections, choose moderate candidates over hard-line ones — at least three of the four presidents who followed Khamenei prove that.

Khamenei doesn’t want to compromise on the revolution’s ideals. But voter partisanship and even divisions among the political class suggest that he has been unable to rekindle the revolutionary zeal.