Mr. Rouhani, a pragmatic centrist when he came to the presidency in 2013, ran to his own left this year. Having concluded the historic nuclear agreement with world powers in 2015, he now emphasized priorities he’d abandoned in his first term: rights, freedoms and the release of the opposition leaders held under house arrest since 2010. He directly challenged the abuses of the judiciary and the political overreach of the Revolutionary Guards Corps, with which he has vied for authority throughout his presidency. What he hadn’t accomplished already, he claimed, he hadn’t been permitted to do. Whether he will be permitted now is a legitimate question, as is the extent of his willingness to battle the judiciary and Revolutionary Guards. But meeting the voting public where it stood meant staking his political capital on the promise to try.

The footage from Mr. Rouhani’s rallies showed a sea of purple, his official campaign color, intermingled with just as much green, the color of the uprising the regime violently quashed in 2009. People held up pictures of that movement’s leaders on their cellphones. Mr. Rouhani has inherited this constituency, and while his embrace of it was tepid in 2013, he seems more comfortable in the role today.

The conventional wisdom about a week before the election held that with youth unemployment over 30 percent, voters were susceptible mainly to pocketbook appeals, cash blandishments of the sort that got Mahmoud Ahmadinejad elected in 2005. And Mr. Rouhani was vulnerable on the economy. He could point to no dramatic dividend from the nuclear deal. Ebrahim Raisi, a hard-line cleric who served on a committee that condemned thousands of political prisoners to death in 1988, dusted off the Ahmadinejad playbook in a campaign that was supposed to galvanize the poor, the religious and the rural villagers. He didn’t lose only in cosmopolitan north Tehran: He performed poorly across the country. This, despite the fact that 2017 by all appearances belongs to the world’s authoritarian populists and the fact that Mr. Raisi enjoyed the apparent favor of the security establishment and of the supreme leader, Ayatollah Ali Khamenei.

There are as many possible reasons for Mr. Raisi’s failure as there are for Mr. Rouhani’s success. Among them is the fact that Iran has abundant experience with populism. There is a whiff of it in the country’s post-revolutionary politics as a whole, whether from left, right or center. But the country has also had a very recent and well-remembered run with a president who made populism his calling card and then proceeded to drive the economy into the ground. Mr. Ahmadinejad’s 2005 rhetoric was politically potent, but the memory of his two terms in office is potent, too.

No election will produce wholesale change in a top-heavy, autocratic regime that has invested everything in its own survival. But the strength of Iran’s evolving civic culture is that it no longer appears to expect this. Twenty years ago, when it first appeared on Iran’s political scene, the reform movement made extravagant promises of democratic development. When President Mohammad Khatami and his idealistic coterie failed to materialize such change during their years in office, from 1997 to 2005, the public turned on them. Widespread voter apathy, cynicism and anger helped bring Mr. Ahmadinejad the presidency in 2005.