Iranian Foreign Minister Javad Zarif, U.S. Secretary of State John Kerry and European Union High Representative Federica Mogherini arrive to deliver statements after nuclear talks April 2 in Lausanne, Switzerland. (Pool/Reuters)

At 10 p.m. on March 27, Secretary of State John F. Kerry strode through the carpeted hallways of the Beau-Rivage Palace hotel in Lausanne, Switzerland, to speak with his Iranian counterpart, Mohammad Javad Zarif. As the two men sat alone in Zarif’s suite, Kerry told him that the U.S. team was ready to abandon more than a year of nuclear negotiations and go home.

For two days, the U.S. delegation had watched the Iranians appear to backtrack from previous agreements on critical issues, including international sanctions and enrichment research. Kerry said he was ready to throw in the towel.

By the time the meeting ended 20 minutes later, Zarif had signaled enough flexibility that Kerry thought it was worth staying, according to senior administration officials familiar with the talks. For one more night, failure was taken off the table.

The near-collapse foreshadows the difficult road ahead as U.S. negotiators aim for a final, comprehensive accord with Iran by June 30.

Will the Iranians stick to what the United States considers their commitments under the preliminary agreement announced on Thursday, or will they try to walk things back again? And will negotiators be able to bridge the remaining, contentious differences and strike a final deal?

President Obama has acknowledged the hurdles that remain.

“Undoubtedly, the Iranians are going to have some differences in terms of how we implement all the things that have been discussed in the political framework, and this drafting process is going to be really, really tough,” he told NPR in an interview that aired Tuesday.

Much about the final week of negotiations is still shrouded in secrecy. The hundreds of reporters in Lausanne, on the shores of Lake Geneva, were kept largely away from the small ground-floor room with red wallpaper where most of the nuclear talks unfolded.

Administration officials have, however, been eager to share the atmospherics of the roller-coaster final negotiations. Those last sessions stretched over eight days, culminating in a grueling nine-hour session that started after 9 p.m. last Wednesday and ended at daybreak the following day. Their accounts could not be independently confirmed, in part because some of the discussions were between Kerry and Zarif alone and in part because the Iranians have not offered their version of events.

The administration officials, speaking on the condition of anonymity because of the secretive nature of the negotiations, recounted their frustration that understandings Washington considered concrete repeatedly proved more malleable to Tehran. The Iranians also often began each round of talks by adopting a harder stance on some issues than they had in the previous session, the officials said.

Kerry arrived in Lausanne in the early hours of Thursday, March 26. That left six days for final negotiations before a self-imposed deadline of March 31. By the end of the second day, how­ever, Kerry was so frustrated at what he considered Iranian intransigence that he braced his staff to be ready to depart that weekend, the officials said.

His late-night visit to Zarif was a last-ditch effort. By that point, the two men had long been on a first-name basis, and Kerry told Zarif that they should together start planning how they were going to manage the news of their failure.

According to administration officials, Zarif, while giving no ground, agreed for the first time to at least put one of the most contentious issues on the table. Officials would not say what the issue was, but the logjam was broken.

Throughout the final week, Kerry had shouldered most of the day-to-day negotiating with Iran. The day after his face-off with Zarif, foreign ministers from the five partners negotiating with the U.S. began to arrive in Lausanne, where Kerry brought them up to speed on what had transpired.

On March 31, speaking from a secure tent erected on the hotel grounds, Kerry appeared on a screen in the White House Situation Room to tell the president and his senior advisers that it was worth continuing the talks a bit beyond the deadline.

But there were still significant hurdles to overcome. Early last Wednesday morning, reporters traveling with Kerry were told to be ready to check out of their hotel rooms later that day. Other foreign ministers left, saying with little enthusiasm that they were prepared to return if it looked like real progress was being made. No one anticipated the all-night negotiating session that was about to begin.

Kerry, Zarif and Helga Schmid, a top European Union official, sat in a small room off the hotel lobby. A table held pastries, fruit and an espresso machine that whirred almost nonstop, fueling everyone but the caffeine-averse Kerry.

Both sides had experts in nuclear physics and sanctions ensconced in nearby rooms, where the tables were covered with empty food boxes and where exhausted scientists occasionally put their heads down for catnaps, as they waited to be consulted on details.

Energy Secretary Ernest Moniz, a nuclear physicist, and Ali Akbar Salehi, the head of Iran’s atomic energy agency, met in a separate room to work through technical issues, periodically joining the negotiators to share the results of their discussions.

Some issues on which the two scientists found solutions didn’t pass political muster, the administration officials said. The Americans said they realized that the Iranians valued their nuclear program as much for what it symbolized in terms of national achievement as for the fuel it provides.

The other foreign ministers eventually started trickling back, but they did not re-enter the talks. At 1:20 a.m., Kerry broke off for a separate meeting with British Foreign Secretary Philip Hammond, French Foreign Minister Laurent Fabius and German Foreign Minister Frank-Walter Steinmeier.

But Kerry and Zarif were back at it just 17 minutes later.

The session, which lasted until almost 6 a.m., ended with a yawn rather than a bang. Everyone was too exhausted to even take stock of where they stood.

After a five-hour break to bathe, talk with their capitals and nap, they regrouped, coming to a “slow realization” that they had enough of an agreement that they could live with it, even if each side would go on to provide different interpretations of some parts of the framework.

After the agreement was announced Thursday night, Kerry gave six television interviews. Then he and his staff went out to a nearby Italian restaurant for dinner with red wine.