Reformists like Ibrahim Asgharzadeh, a leader in the American Embassy takeover, are another important force. Mr. Asgharzadeh now advocates better ties with America and is working to reform Iran’s political system so that the role of the military is diminished and ordinary citizens have more freedoms and a greater say in politics.

A third factor is the huge population of young people (more than half of Iran’s 80 million people were under 35 in 2012) who worry most about getting jobs in an economy crippled by international sanctions and Mr. Ahmadinejad’s mismanagement and corruption. In one of Iran’s paradoxes, technology stores in Tehran are jammed with the latest Apple laptops and iPhones (or good imitations) despite punishing international sanctions, yet the state coffers are nearly empty.

THE shift created by Mr. Rouhani’s election does not, however, alter the regime’s radical underpinnings or erase the power of hard-liners working against international engagement and any loosening of the Iranian system. Among them is Hossein Shariatmadari, whose business card describes him as the “Supreme Leader’s representative” at Kayhan, Iran’s leading conservative newspaper. He did not support Mr. Rouhani, does not believe in compromise with the United States and warned, in an interview this month, that if nuclear negotiations fail and America or Israel takes military action against Iran’s nuclear program, “Iran will retaliate.”

Even the most optimistic advocates of Mr. Rouhani’s agenda are convinced that if the nuclear deal fails and he is unable to get sanctions lifted in time to revive the economy, radical Islamists will resurge more powerfully than before. While rigid controls on socializing, head covers for women, music and political discourse have relaxed somewhat in recent months, people are still fearful. Street musicians and student activists, for instance, were willing to talk about their activities but did not want their last names published.

Still, these dark forces were not the dominant impressions of my trip. At a mosque in the ancient city of Isfahan, I met two dozen male college students, all of them enthusiastic about speaking to an American. They were eager to debate United States policy and expressed remarkable affinity for the country some Iranians still call “the Great Satan.” Their generation represents Iran’s best hope for opening its future to the world.