This happened once before.

A decade and a half ago, there was a moderate, reformist president in Tehran, Mohammad Khatami, who famously supported a “dialogue of civilizations” and who once even shook hands with Israel’s president. In 2001, following the US invasion of Afghanistan, Khatami’s Iran played a critical role in helping the United States put together a new government in Kabul. In 2003, members of Khatami’s circle, through Swiss channels, offered a tentative proposal, dubbed the Grand Bargain, to the United States, seeking to resolve a host of outstanding issues between the two countries. And, in a show of good faith, Khatami initiated negotiations with Britain, France, and Germany over Iran’s nuclear program, with Hassan Rouhani as the lead diplomat.

You already know that this story doesn’t end well.

President George W. Bush, in his 2002 State of the Union address, lumped Iran in with Iraq and North Korea as the “Axis of Evil,” the United States cavalierly dismissed the Grand Bargain, and it didn’t support the talks between Iran and the EU-3. “That really handed Iran over to the hard-liners,” says Hadi Ghaemi, executive director of the New York–based Center for Human Rights in Iran (CHRI). “It undermined Khatami, and it led directly to the election of Mahmoud Ahmadinejad.”

Fast-forward to 2017. That same Hassan Rouhani is now Iran’s president, running for reelection next month. Four years ago, having built a coalition of young people, women, liberals, reformists, and the business community, he defeated an array of hard-liners, pledging to end Iran’s international isolation, restore the economy, and open up the country’s civil society. “I have come to destroy extremism,” Rouhani declared during his 2013 campaign, a not-so-subtle reference to Ahmadinejad, his predecessor. During his first term, Rouhani engineered the breakthrough Joint Comprehensive Plan of Action (JCPOA), the accord between Iran, the United States, and five other world powers to end the long-running nuclear standoff.

Now, with the first round in the election set for May 19, it’s not impossible that history will repeat itself. Rouhani will face off against Ebrahim Raisi, a far-right, ultra-religious extremist, as his most prominent challenger, as well as a hard-line former military commander, Mohammad Bagher Qalibaf. And while it is widely believed, inside Iran and among Iran-watchers in the United States, that Rouhani will win, the harsh anti-Iran rhetoric emanating from the White House—including Donald Trump’s repeated denunciations of the US-Iran nuclear deal—could undermine Rouhani’s reelection bid and add fuel to charges by hard-liners that Rouhani is too close to the West.

It didn’t help when, on April 19, Secretary of State Rex Tillerson, who grudgingly affirmed to Congress that Iran is complying with the JCPOA, went on to denounce the deal and accuse Iran of “provocative actions [that] threaten the United States.”

A win by the hard-liners would raise the stakes in the standoff between the United States and Iran. The Trump administration would likely continue an escalating pattern of actions that risk triggering a response by Tehran. And with ultra-conservatives back in charge, the chances that Iran would react aggressively in the event of a minor incident—such as a repeat of the gunboat clash that occurred in the Persian Gulf in January—would rise to dangerous levels.

Under normal circumstances, Rouhani ought to be able to coast to victory.

Last time around, he won an outright majority in the first round, avoiding the need to compete in a two-person runoff. He delivered on his central promise, the nuclear agreement, which many Iranians hope will lead to an economic resurgence with the lifting of most international trade sanctions, a rise in Iran’s oil exports, and a surge in European, Russian, Chinese, and other countries’ investment. The nuclear accord is favored by a majority of Iranians, polling shows, though enthusiasm for it has been cut in half since it was announced two years ago, with 21 percent saying that they “strongly approve” of the JCPOA and another 34 percent saying that they “somewhat approve.” Since August 2015, those totals have dropped, from 43 percent strongly approving and 33 percent somewhat approving.

Still, Rouhani and his allies, including moderates, reformists, and urban liberals, won a sweeping victory in the parliamentary elections in February 2016, and many of the hard-liners who opposed the JCPOA went down to defeat.

But Rouhani has reason to be nervous.

First of all, many Iranians appear to believe that Rouhani overpromised on the results of the JCPOA. Though oil exports are up, tripling from 900,000 barrels a day to 2.6 million in the first year after sanctions were lifted, there’s been little impact so far on the day-to-day lives of Iranians. According to a poll by the Center for International and Security Studies at the University of Maryland, “A year after the deal was implemented and nuclear-related sanctions on Iran were lifted, majorities believe that Iran has not received most of the promised benefits and that there have been no improvements in people’s living conditions as a result of the nuclear deal.”

Part of the reason why things haven’t improved is that the West has maintained stringent, non-nuclear-related sanctions on Iran, which has put a damper on foreign investment and trade between Iran and Western countries. “The United States and the EU still have human-rights and terrorism sanctions in place, so many countries have refused to invest in Iran,” says Ahmad Majidyar, director of the IranObserved Project at the Middle East Institute in Washington. “As a result, economic growth has not trickled down to ordinary Iranians.”

Trita Parsi, president of the National Iranian American Council (NIAC), says that international financial institutions are worried about what’s to come, too, from the Trump administration. “Banks are very, very nervous,” says Parsi. “They fear that they could be hit by astronomical penalties if they deal with Iran. The regulations are mostly gone, but the fear remains.” So far, he says, the White House has not discouraged legislation moving forward in Congress to impose new, tougher sanctions on Tehran.

For the hard-liners in Iran, also known as the “principlists,” all of that creates an opening. “Just as they did with Bush, with Trump the hard-liners will try to capitalize again,” says Ghaemi. By mid-April, at least half a dozen credible hard-line candidates had entered the race, jockeying to represent Iran’s deep state, including the Iranian Revolutionary Guard Corps (IRGC), the intelligence and security agencies, the judiciary, the police, the paramilitary Basij militia, and, of course, the ultraconservative clergy. In 2013, several hard-liners competed against Rouhani, splitting the right’s vote. This time around, the principlists will have learned from that mistake, say Iran experts, and they’ll ultimately seek to consolidate under one consensus standard-bearer.

Many of them, overtly or covertly, opposed the JCPOA, and they’re well aware that Rouhani will try to use it to his advantage in the election. Shahir Shahidsaless, an Iranian-Canadian political analyst writing for the Atlantic Council’s IranInsight, reports that in December an editorial in the IRGC’s journal Sobhe Sadeq described the JCPOA as Rouhani’s “winning card.” But the paper denounced it, calling it “a tool to erode the authority of the Islamic Republic by attempting to not only halt Iran’s increasing empowerment but also to gradually transform our country into an ally and a client country thus solidifying the position of the Zionist regime in the region.” As we shall see, it will be tricky for the opposition to use the JCPOA against Rouhani.

In advance of the election, Iran’s security services have been conducting a crackdown aimed at Rouhani supporters and social media, especially the wildly popular Telegram app, which has 20 million followers in Iran. Scores of Telegram channels have been shut down since the beginning of the year, and dozens of people—mostly pro-Rouhani journalists on Telegram—have been arrested, probably the harbinger of a wider assault as the election gets closer. Virtually all of Iran’s broadcast media are controlled by hard-liners, says the Middle East Institute’s Majidyar.

Ahmadinejad, a favorite Western bogeyman, whose grinning visage and nonstop provocative comments—including denying the Holocaust—made him a loathed figure in the United States, tried to elbow his way into the field. He reportedly stunned pundits inside and outside Iran by filing to run. Yet the all-powerful Guardian Council, a secretive body of 12 clerics, refused to approve Ahmadinejad’s candidacy. The Guardian Council’s decision wasn’t entirely surprising (in 2013, it barred another former president, the late Ali Akbar Hashemi Rafsanjani, from competing), since Ahmadinejad had been warned by Iran’s supreme leader, Ayatollah Ali Khamenei, not to run. During his second term (2009–13), Ahmadinejad veered erratically toward an odd sort of nationalist populism, at times seeming to prioritize Persia’s ancient, pre-Islamic empire over Islam itself, annoying Khamenei. In preparing for this year’s race, Ahmadinejad joined Twitter—no doubt mimicking America’s tweet-happy president—and one of his first tweets showed him posed heroically in front of the ruins of Persepolis, a not-so-subtle reference to old Persia. He likely thought he could run a populist campaign focused on his supporters among the country’s disenfranchised poor. But he faced a “backlash from conservatives,” says Majidyar.

The Guardian Council approved two leading hard-liners out of a wide field. Qalibaf, the conservative mayor of Tehran, is a former IRGC commander with strong appeal among the principlists, and in 2013 he finished second to Rouhani, winning 6 million votes. But Raisi probably poses the most serious threat to Rouhani. “The entry of Raisi into the race wasn’t anticipated even [three] weeks ago,” says Gary Sick, professor of international and public affairs at Columbia University and a former aide to President Jimmy Carter on Iran. Raisi is widely considered to be heir-apparent to 77-year-old Supreme Leader Khamenei. A lifelong hanging-judge prosecutor, deputy chief justice, and attorney general, last year Raisi was named to the prestigious post of chairman of a multibillion-dollar Islamic foundation in Iran’s holiest city, Mashhad, where his father is the Friday prayer leader and Raisi himself is an influential clergyman.

What endears Raisi to the hard-liners is precisely what alarms moderates and reformists: his track record as a repression-minded jurist. In 1988, Raisi led a panel of overseers, since dubbed the Death Committee, that ordered the mass execution of about 5,000 political prisoners. “He was part of the most atrocious crime in contemporary Iranian history,” says the CHRI’s Ghaemi. “It was a massacre of thousands.” But Raisi has won, or is likely to get, the backing of a broad coalition of hard-liners assembled under the rubric of the Popular Front of Islamic Revolution Forces and its constituent parts, with names such as the Resistance Front of Islamic Iran, and the powerful Combatant Clergy Association. (Political parties don’t exist in Iran, but ad-hoc groupings of elite forces come and go, representing some combination of ayatollahs, military commanders and veterans, and their allies.)

In the early stages of the campaign, both Raisi and Qalibaf have signaled that they intend to run as populists, appealing to Iran’s urban poor and to its rural, impoverished class by pledging to institute a robust system of welfare handouts. That, too, was a tactic used effectively by Ahmadinejad during his presidency, when he sought to consolidate support among underprivileged voters. But the Raisi-Qalibaf tactic drew a sharp rebuke this week from Ali Larijani, the speaker of Iran’s Parliament and one of five powerful brothers in Iran’s conservative establishment, who called it “not feasible” to increase Iran’s subsidy program. Though the meaning of the intervention by Larijani isn’t clear, it could be a signal that the conservative bloc is, at the very least, divided about the wisdom of ousting Rouhani.

The hard-liners in Iran have their counterparts in the United States. Not only did Trump threaten to tear up the JCPOA on taking office—something that, thanks in part to strong pressure from current and former US officials, he so far has failed to do—but he’s put in place a team of officials, led by Defense Secretary James Mattis, who see Iran as a dire threat. “[Mattis] was so hawkish on Iran as head of United States Central Command from 2010 to 2013 that the Obama administration cut short his tour,” reported The New York Times in December. “Iran is not a nation-state,” said Mattis in a speech in April 2016 at the Center for Strategic and International Studies in Washington. “It is a revolutionary cause devoted to mayhem.” Following a series of incidents at sea and a recent Iranian missile test, Gen. Michael Flynn, later relieved of his duties as national-security adviser, put Iran “on notice”—whatever that meant. And Trump’s attempt to impose a Muslim travel ban, targeting Iranians along with residents of five other Muslim countries, angered Iranians.

In addition, in February the White House signaled that it was considering designating Iran’s IRGC, essentially its main military force, as a terrorist organization, which could trigger a new wave of economic and political sanctions. The White House ordered a new set of sanctions against Iran for its late January ballistic-missile tests, even though the tests do not violate the JCPOA. And it supports a series of new sanctions bills working their way through Congress, led by Senator Bob Corker’s Countering Iran’s Destabilizing Activities Act (S. 722), which has garnered more than 30 Senate co-sponsors. In a sign that even Corker is wary of provoking Iran’s hard-liners just weeks before the vote, however, he has decided to stall the legislation. “We’ve got a Iran sanctions bill that has a number of co-sponsors that wasn’t able to markup at present because of concerns about how the European Union might react and (Iranian) elections that are coming up,” said Corker.

So what will happen? Gary Sick cautions that Iranian presidential elections are known for surprising twists and turns. “Just about everybody I know has been wrong about Iranian elections,” he says. But Sick argues that when they go to the ballot box, voters are likely stick with Rouhani. “He’ll argue: ‘We’ve dealt with the Great Satan. We’re pretty good at it. It’s worked to our benefit. So, whom do you trust? Do you want to go back to the days when all we did was shout at the United States?’”

Echoing Sick is Farideh Farhi, an Iran expert and affiliate faculty member at the University of Hawaii, who has also taught politics at the University of Tehran and at Shahid Beheshti University in Tehran. “If the JCPOA comes up in the campaign, it’s going to put Rouhani’s opponents in a difficult position,” she says. “What are they going to say? Abolish the JCPOA? Don’t forget, the Ayatollah Khamenei has approved it. And Rouhani hasn’t backed down on other issues, on Syria, on Iran’s missile program, on Iraq.”

Farhi points out that when Rouhani filed his petition to run for reelection, he took the issue on directly, making the Iranian version of the argument against changing horses in midstream. “[Those] who had repeatedly made decision to kill this child, the BARJAM”—as the JCPOA is known in Persian—“cannot be a good caretaker for it,” Rouhani said. “Rather, the same people who worked day and night for the agreement should continue the path until the last step.”

As always in Iran, the decisive role is likely to be played by Supreme Leader Khamenei. In 2009, when Ahmadinejad ran for reelection, it was widely reported that the vote-counting was rigged in his favor—and, in any case, Ahmadinejad’s two main challengers, Mir-Hossein Mousavi and Mehdi Karroubi, remain under house arrest eight years later. “If,” says Sick, “the entry of Raisi is a signal that the supreme leader has turned against Rouhani, that would throw every prediction into a cocked hat.”