Iranian President Hassan Rouhani staked his political future on opening Iran ever so slightly to the outside world and overcoming hardliners’ opposition to secure a historic nuclear deal in exchange for relief from crippling sanctions.

The 68-year-old cleric, a moderate within Iran’s political system, has history on his side as Iranians vote for President on Friday. No incumbent President has failed to win re-election since 1981, when Ayatollah Ali Khamenei, the current Supreme Leader and most powerful man in Iran, became President himself.

Polling data that’s available suggests Mr. Rouhani will come out on top among the four candidates left running, though an outright win is not assured. Failure to secure a majority would send the two top candidates into a run-off a week later.

The rallies were largely peaceful even as Rouhani supporters faced off against smaller crowds supporting his main rival, hard-liner Ebrahim Raisi, though police rushed reinforcements to break up Rouhani rallies that grew large enough to block traffic.

Working against Mr. Rouhani is a sense among many Iranians that the 2015 nuclear deal, which saw Iran accept limits on its atomic energy program, has failed to deliver an economic windfall.

“No matter who’s the next president, whoever comes to power should bring a better economy,” hair stylist Reza Ghavidel said.

Although nuclear-related sanctions were lifted because of the deal, other U.S. and other international sanctions remain in effect. That leaves banks and many big corporations wary of doing business with Iran.

Unemployment, meanwhile, remains stuck in the double digits, with nearly a third of Iranian youth out of work, according to the International Monetary Fund.

“This election is about the economy. I don’t think most voters are thinking about the soul of the nation right now,” said Cliff Kupchan, the chairman of the Eurasia Group. “The numbers are looking better ... but the voters aren’t feeling it.”

Mr. Rouhani’s stiffest challenge comes from Mr. Raisi, a law professor and former prosecutor who heads an influential religious charitable foundation with vast business holdings. He is seen by many as close to Mr. Khamenei, and has even been talked about as a possible successor to him. Mr. Khamenei has stopped short of endorsing anyone.

Mr. Raisi won the support of two major clerical bodies and promised to boost welfare payments to the poor. His populist posture, anti—corruption rhetoric and get-tough reputation bolstered by his alleged role condemning inmates to death during Iran’s 1988 mass execution of thousands of political prisoners are likely to energize conservative rural and working-class voters.

In a bid to woo younger voters, he has even turned to appearing in a viral video next to a tattooed, once-underground rapper named Amir Tataloo despite his own history of supporting the cancellation of concerts on moral grounds.

Mostafa Hashemitaba, a pro-reform figure who previously ran for president in 2001, and Mostafa Mirsalim, a former culture minister, also remain in the race.

The ruling system put in place after the 1979 Islamic Revolution combines conservative clerical oversight and state control over large parts of the economy with tightly regulated but still hotly contested elections for key government posts. All candidates for elected office must be vetted, a process that excludes anyone calling for radical change, along with most reformists. No woman has been approved to run for President.

Under Iran’s system, the President is subordinate only to the supreme leader, who is chosen by a clerical panel and has the ultimate say over all matters of state. The presidency is still a powerful post, with considerable influence over domestic policy, the state bureaucracy and foreign affairs.

A victory for Mr. Rouhani could lead to a further loosening of limits on personal freedom, while a hard-line win could set Iran up for a renewed bout of confrontation with the West at a time when U.S. President Donald Trump has called for a tougher line on Iran.

Mr. Trump will be in Saudi Arabia, Iran’s regional rival, as votes are tallied. He will meet with Sunni Arab leaders who are opposed to Iran’s backing of Syrian President Bashar Assad and remain sceptical of its regional intentions.

Whoever wins Friday’s vote could help shape the choice of the next supreme leader, and in turn the direction of the country.

Mr. Khamenei is 77 years old and only the second person in Iran’s history to hold the top job. He underwent prostate surgery in 2014, prompting speculation about his health.

The President is one of three members on a temporary council that takes over the supreme leader’s duties should his post become vacant until a successor is named by the panel known as the Assembly of Experts. Mr. Rouhani and Mr. Raisi both sit in that assembly.

“The game is very complicated and multi-layered. Everyone’s thinking about the next four years and the succession of Ayatollah Khamenei,” said Saeid Golkar, an expert on authoritarian regimes and Iran at Northwestern University.

The three-week campaign has been marked by boundary-pushing politicking among what were originally six candidates.

Mr. Rouhani has come out swinging against hard-liners, including the powerful Revolutionary Guard, which plays an outsized but unelected role in Iranian politics. In one memorable debate moment, he criticized the Guard for launching a ballistic missile bearing the words “Israel must be wiped out” in Hebrew.

Turnout will be key no more so than for Mr. Rouhani. Reformists and moderates tend to fare better when more voters make it to the polls, and a head-to-head runoff against Mr. Raisi is something he will want to avoid. City council elections alongside the presidential vote are likely to attract more voters in the first round, and the start of the holy month of Ramadan late next week could keep voters home during a runoff, Mr. Golkar said.