GENEVA — At 2:04 a.m. Sunday, a one-word e-mail message flashed suddenly on the phones of weary State Department staffers working the corridors of Geneva’s InterContinental Hotel.

“DEAL.”

In four characters, the message signaled an improbable success: an agreement, reached in 60 days of marathon bargaining, to impose sweeping restrictions on Iran’s nuclear program. Only it wasn’t quite true.

Within minutes of the e-mail’s arrival, Iranian officials interrupted a meeting of Western diplomats to announce a last-minute hitch: Tehran had found a new objection in the wording of the agreement and wanted to re­negotiate. As had happened many times over the course of the talks, a pact that seemed so close to being finished appeared at risk of veering off track.

The dispute was soon resolved, but the moment encapsulated the volatility — and occasional gut-churning intensity — of the bargaining process that yielded Sunday’s historic nuclear agreement. Despite the willingness of the parties, including American and Iranian presidents who strongly favored a deal, the talks progressed in fits and stumbles up to the 3 a.m. signing ceremony, when the visibly exhausted diplomats arrived at Geneva’s Palace of Nations to confirm that they did, truly, have a deal.

Along the way were moments of humor and genuine warmth among emissaries from countries that have been virtually at war for more than three decades. But the sessions also witnessed sharp disagreements among the P5+1 countries — the bloc of six major powers (the United States, Britain, China, France, Germany and Russia) that negotiated the deal with Iran — and more than a few angry outbursts as Iranian diplomats railed against proposed changes introduced late in the bargaining.

“It was dramatic at times,” said one Western official who had an up-close view of the negotiations as they unfolded over three grueling sessions in this iconic Swiss city. “There was a sense that people were moving toward an agreement, but there were periods when it looked to be falling apart — real skin-of-the-teeth moments.”

Twice, as the talks appeared to be faltering off and on over the past month, foreign ministers, including Secretary of State John F. Kerry, staged dramatic interventions, jetting to Geneva with entourages of aides, journalists and security guards. On the first such occasion, the diplomats returned home empty-handed.

But Kerry’s personal influence appeared to help, and in ways that were not immediately obvious during the negotiations. Administration officials revealed that Kerry had been working quietly through Omani intermediaries to reach out to Iranian moderates since 2011, two years before he was named President Obama’s second-term secretary of state.

After moderate cleric Hassan Rouhani was elected Iran’s president in June on a promise to end the country’s diplomatic isolation, Kerry held his first meeting with Rouhani’s foreign minister, Mohammad Javad Zarif, on the sidelines of September’s U.N. General Assembly meeting in New York. The men spoke twice afterward, in October and early November, a senior administration official said. The two appeared to have developed a strong rapport by the time they met on Nov. 10, when Kerry flew to Geneva in a failed attempt to jump-start the flagging nuclear talks.

When the negotiations resumed Wednesday, Kerry monitored the progress from Washington before deciding whether to intervene. The reports were initially discouraging. After a 10-day lull between talks, the Iranians had returned to Geneva with new demands — tit-for-tat, they said, for last-minute changes introduced by France during the previous round. On Thursday, when the U.S. negotiating team broke for dinner at Luigia’s restaurant, it was unclear whether an agreement was possible.

Kerry flew to Geneva the next evening. After arriving early Saturday, he met with Zarif and his team to deliver a blunt warning: Kerry would not be able deter Congress from imposing new sanctions on Iran if the negotiations failed. Zarif also was acutely aware that time for a deal could be waning.

“The Iranians used to use negotiations to buy time, but during this round they were clearly eager to move forward,” said a Western diplomat involved in the talks who, like others, spoke on the condition of anonymity.

Throughout the day Saturday, the parties made steady progress in narrowing the differences. One of the remaining sticking points, according to sources familiar with the negotiations, involved Iran’s controversial, partly completed heavy-water reactor near the city of Arak. U.S. officials fear that the reactor, if completed, could give Iran a potential supply of plutonium, which can be used in nuclear weapons.

Zarif’s team agreed that Iran would not put nuclear fuel inside the reactor during the six-month interim agreement, but the Americans wanted more. Kerry’s team insisted that Iran cease all work on building components for the reactor, including testing of nuclear fuel.

Negotiators then haggled over whether the final agreement would recognize Iran’s “right” to enrich uranium. Zarif and his team repeatedly insisted that they needed explicit language about enrichment in the text in order to sell the deal back home. The U.S. rejected any mention of an enrichment “right” and pushed for vague language referring to Iran’s ability to seek peaceful nuclear power in a “mutually defined” way.

“In the end, we were negotiating over a small number of words,” said a U.S. official familiar with the discussions.

A final bout of haggling occurred during a late-night meeting between Kerry, Zarif and Catherine Ashton, the mild but indefatigable European Union foreign chief who led the P5+1 side and worked tirelessly to keep the parties talking. Zarif, exhausted after four days of nearly nonstop bargaining, reportedly griped to Kerry, complaining that the Western negotiators had repeatedly “moved the goal posts,” in the words of a senior Western diplomat familiar with the exchange.

That meeting broke up just after 10 p.m., when the delegations returned to their hotel rooms. Final fixes to wording were proposed and debated by phone as aides raced down the hotel corridors with copies of the draft text.

Just after 2 a.m. Sunday, with all sides apparently in agreement, U.S. negotiators sent out word by e-mail of a “DEAL.” Then they were forced to backtrack when the Iranians, after consulting with government officials in Tehran, tried to push for one more change. The nature of the proposed tweak was not disclosed.

Ashton and the other delegation leaders conferred briefly and rejected the request.

“By then it was just too late,” a second Western diplomat said. “The deal was already done.”

Comments our editors find particularly useful or relevant are displayed in Top Comments, as are comments by users with these badges: . Replies to those posts appear here, as well as posts by staff writers.

To pause and restart automatic updates, click "Live" or "Paused". If paused, you'll be notified of the number of additional comments that have come in.

Comments our editors find particularly useful or relevant are displayed in Top Comments, as are comments by users with these badges: . Replies to those posts appear here, as well as posts by staff writers.

Spam

Offensive

Disagree

Off-Topic

Among the criteria for featured comments: likes by users, replies by users, previous history of valuable commenting, and selection by moderators.

Content from Allstate This content is paid for by an advertiser and published by WP BrandStudio. The Washington Post newsroom was not involved in the creation of this content. Learn more about WP BrandStudio.