Mr. Salehi, 66, will have his own problems selling an agreement to the generals and clerics in Tehran, many of whom are suspicious of Iran’s Western-educated negotiators and will have to be convinced that Iran has not backed down in the face of American demands. In recent days, Mr. Salehi has taken a decidedly positive tone in public, suggesting that all technical disputes with the United States have been resolved — a move some American officials interpret as an effort to put the blame squarely on Washington if the talks fail.

“For both sides, there are big questions of optics and politics here,” Mr. Moniz said.

People who know both men say they have more in common than challenges at home.

They are “mirror images in different contexts, both very personable,” said Michael J. Driscoll, an emeritus professor of nuclear science and engineering at M.I.T. who advised Mr. Salehi on his dissertation. Over the years, Mr. Salehi fell out of contact with Mr. Driscoll and many of his M.I.T. colleagues, who were warned after the 1979 Iranian revolution, which swept out the Washington-supported shah and brought to power a virulently anti-American Islamic leadership, that corresponding with Mr. Salehi could place him in jeopardy.

Mr. Salehi and Mr. Moniz converged a little more than a month ago in the increasingly tense talks, brought together after the Iranians announced that Mr. Salehi, a former foreign minister who represented Iran at the International Atomic Energy Agency in Vienna, would have a seat at the negotiating table. It was a telling move: Mr. Salehi is considered close to Iran’s supreme leader, Ayatollah Ali Khamenei, and behind the scenes in Tehran, he had just killed an American proposal to reconfigure Iran’s centrifuges in a way that would have made them far less capable of producing enriched uranium.

Soon, Mr. Moniz received a call from the White House: He would become Mr. Kerry’s negotiating partner.

Mr. Moniz was well suited for the job: After becoming energy secretary nearly two years ago, he brought in scientists from the United States’ national laboratories to work out options to present to the Iranians, based in part on a secret replica of Iran’s facilities that the United States built when it was mapping out cyberattacks against them during the Bush administration.