A tech entrepreneur: “Don’t judge Iran just by what the clerics say at Friday prayers.” Illustration by Emiliano Ponzi

As the diplomacy on Iran’s nuclear program entered a final phase, in Europe, I visited the tomb of Ayatollah Khomeini, the ideologue of Iran’s 1979 revolution, in Tehran. One of the grandest mausoleums in the world—its shimmering dome is visible for miles—was under expansion. The Imam’s bare receiving room, in his home, was preserved after he died, in 1989, in tribute to his modesty, but renovations at his tomb featured vaulted ceilings, lined with intricate mosaics, that soared stories high, and epic arches adorned with tiles in many shades of blue. In death, Khomeini’s body is in surroundings grander than the palaces of Persian kings. Editorials compared the opulence to Hollywood sets and condemned the costs at a time of poverty among the living.

The shrine has a metro stop. The faithful still visit. But numbers are down, and so is the fervor that mobilized millions during the revolution. In a space that holds thousands, I saw some two hundred pilgrims and a group of Dutch tourists.

Meisam Shahbani, a twenty-seven-year-old factory worker, tries to visit the tomb once a year, with his wife. “For each country, one person is important,” he said. “Maybe for the United States it was the first President. Khomeini was our leader.” Shahbani also likes the pop music of Enrique Iglesias and Christopher Nolan’s films, including “Batman Begins.” He favored a nuclear deal with the United States, too, especially if jobs are created by the lifting of sanctions. “Anything that will improve the situation in Iran,” he said.

The next day, Iran commemorated the Prophet Muhammad’s Night Journey and Ascension to Heaven on a mythical steed. I spent the evening with two Iranian professors, Nasser Hadian and Bahram Taheri, old friends who had taught at Columbia and the University of Michigan, respectively. We went to an open-air restaurant, then strolled through Water and Fire Park, one of hundreds of landscaped spaces in Tehran. The center fountain is surrounded by towers that shoot off balls of fire. Opened in 2009, the park has playgrounds, terraced gardens, a planetarium, an outdoor arena, and a man-made lake, with swans. At midnight, thousands were still picnicking. Little kids on pastel bikes were weaving through the crowd. Western pop music echoed from the concrete hills of a roller park. We stopped to watch skateboarders and rollerbladers vying, at dangerous speeds, on steep half-pipe curves. A cell-phone company was hosting a show of comedians and other celebrities in the arena; it was packed. Camera crews were taping it for television.

I remarked on how much Iran had changed since the revolution, when I was nervous driving after dark, because cars were stopped at nighttime checkpoints to verify that the women inside were related to the men. Neighborhood komitehs raided homes suspected of partying and prowled streets to confront women who wore lipstick or exposed their ankles.

“You just have to go to this park to understand the state of mind among Iranians today,” Hadian, a political scientist now at the University of Tehran, said. “The revolution is in a midlife crisis. What is a midlife crisis? When you think idealism and youthfulness are gone. The revolution doesn’t want to accept that it has grown older, that it won’t achieve everything it wanted to achieve. Or that it has to adapt to survive.”

We reached the end of the park just as fireworks celebrating the Prophet’s heavenly journey went off over Tehran. People scrambled to get selfies against the flashing night sky.

In “The Anatomy of Revolution” (1938), the Harvard historian Crane Brinton likened revolution to fever. The first stage is raging delirium, as ruthless radicals eliminate the ancien régime and purge their moderate collaborators. In the second, societies begin a long, fitful convalescence, often under dictatorial rule, as the “mad religious energy” subsides. The final stage is recovery and a return to normalcy, which may even include remnants of the past, as “the religious lust for perfection” dies out, “save among a tiny minority.”

Iran’s revolutionaries are aging. Most are in their late fifties, sixties, or seventies. The Supreme Leader, Ayatollah Ali Khamenei, turned seventy-six this month. More than sixty per cent of Iran’s eighty million people are under the age of thirty-five. A baby-boom generation, born after the revolution, doesn’t share all of its priorities.

“It’s a tsunami,” Said Rahmani, the C.E.O. of Sarava, Iran’s first venture-capital fund, told me. “This generation is worldly. They’re educated. They work. They have spending power. They’re not dependent on anyone. They have a different range of thinking.”

These days, the energy—and the locus for charting Iran’s future—is less in heady debates about an ideal Islamic state than in a practical scramble to exploit twenty-first-century technology to change society. More than a third of the population uses the Internet. Giant billboards for a new smart-phone model were plastered across Tehran this summer: “NEXT IS NOW.”

One afternoon, I drove to a huge warehouse on Tehran’s outskirts to see Saeed and Hamid Mohammadi, thirty-six-year-old identical twins. They are groundbreakers in the first generation of startups in Iran. In 2007, they created Digikala, the Amazon of Iran. It accounts for more than eighty per cent of online retail, according to Hamid. The Economist reported its value last year at a hundred and fifty million dollars.

The twins took me on a tour of the warehouse. A red motorcycle—the company’s iconic delivery vehicle—decorated the lobby. Aisle after aisle had shelves stacked with computers, refrigerators, books and DVDs, home appliances, perfumes, electric toothbrushes, guitars. Digikala sells Steinway pianos. An Iranian-American in California had just ordered a Mother’s Day present for delivery in Tehran, Hamid said.

For centuries, the bazaar was the heart of Iran’s economy, and one of the three traditional arms of power, with the clerics and the military. In 1979, the Shah was forced to abandon the Peacock Throne after the bazaaris and the clergy turned on him. The bazaar is still a big player, but Digikala and other startups have created a new space in society; the twins are proudest of the flow of information in customer reviews. E-commerce increasingly defines market prices, too.

“Five years ago, the profit margin for consumer electronic goods sold in Iran was nine or ten per cent,” Hamid said. “Because of e-commerce, the traditional market now can’t sell for more than three or four per cent. We forced the market down—and made a fortune in the process.”

The Internet is also “one of the central battlegrounds between hard-liners anxious to control all expression and access in Iran and the majority of the population,” according to the International Campaign for Human Rights in Iran. Many Iranians use virtual private networks to circumvent censorship of millions of Web sites and social media—and so do many of the theocrats. The Supreme Leader and the President have taken to using Twitter, Facebook, YouTube, and Instagram to propagate their messages, in Farsi and in English.

The rivalry for Iran’s future has played out over WhatsApp, Viber, and Tango. All three are used heavily to make free calls, send messages, and post photos or videos. They’re also ways to share the deliciously naughty political humor that Iranians love, without getting caught by the Committee to Determine Instances of Criminal Content. The committee, which is part of the Ministry of Justice, can prosecute people for an array of vague offenses, including “disturbing the public.” It was sanctioned by the United States in 2013 for barring freedom of expression. Last year, the regime proposed “smart filtering,” instead of blocking sites altogether. But it may already be too late to totally monitor the Internet in Iran.