And conservatives around the supreme leader, Ayatollah Ali Khamenei, were looking for any signs that their Americanized chief negotiator, who studied at the University of Denver, was ready to give away too much nuclear infrastructure without getting Iran the sanctions lifted in return, as the ayatollah had decreed.

There was no single event, no heart-to-heart conversation between adversaries or game-changing insight that made the Iran deal happen. Instead, over a period of years, each side came to gradually understand what mattered most to the other.

Image Mr. Moniz has a Massachusetts Institute of Technology connection with Ali Akbar Salehi. Credit... Kevin Lamarque/Reuters

For the Americans, that meant designing offers that kept the shell of Iran’s nuclear program in place while seeking to gut its interior. For the Iranians, it meant ridding themselves of sanctions in ways they could describe to their own people as forcing the United States to deal with Iran as an equal, respected sovereign power. And in the end they reached agreement because a brief constellation of personalities and events came into alignment:

The sultan of Oman, who convinced the White House that he could establish a back channel to the Iranians. The election of Mr. Rouhani, who Mr. Obama thought would be more receptive to his overtures than Iran’s aging supreme leader. A series of insights from the Energy Department’s nuclear laboratories that allowed the physics of enrichment to create new space for compromise among the political leaders. And the presence of two top diplomats, Mr. Kerry and Mr. Zarif, driven by the conviction that they could break an ugly 35-year history.

At one point last week the simmering tension between the two negotiators boiled over when Mr. Zarif felt his American counterpart was pressing too hard. “Never threaten an Iranian!” he shouted. At the other end of the table Sergey V. Lavrov, the Russian foreign minister, who has had his share of disputes with Mr. Kerry, tried to break the tension. “Or a Russian!” he said, as the room broke out in nervous laughter.

But during a break on one particularly discouraging March day in Lausanne, Switzerland, where negotiations were held before adjourning to Vienna, Mr. Zarif struck a different tone as he invoked the names of the key figures on two sides, including Vice President Joseph R. Biden Jr. and the top energy officials of the United States and Iran, Ernest J. Moniz and Ali Akbar Salehi.

“We are not going to have another time in history when there is an Obama and a Biden and a Kerry and a Moniz again,” he said, according to notes of the conversation. “And there may be no Rouhani, Zarif and Salehi.”