Iran nuclear talks: Behind the scenes at Lausanne
Sleepless nights punctuated by passionate outbursts characterized an extraordinary week of negotiations in Switzerland that led to an historic framework agreement on Iran's nuclear programme.
The US Secretary of State John Kerry admitted to the BBC there was at least one point when he thought he might walk away from the table.
Senior US administration officials described a rollercoaster round of fiendishly complex negotiations with uncertainty about the outcome right to the end.
The following is based largely on their accounts to reporters after the announcement of a broad understanding on steps to curb Iran's nuclear activity in exchange for lifting sanctions.
Seasoned American negotiators began the week by plotting out a work plan with their Iranian counterparts. The Iranians were obliged to take anything on paper back to Tehran and didn't want to tie their hands in that way, so the joint drafting was done on a dry-erase whiteboard.
Coming and going
Mr Kerry and his Iranian counterpart Javad Zarif led the political negotiations. Top nuclear scientists - the US Energy Secretary Ernest Moniz and Iran's Atomic Energy Chief Ali Akbar Salehi - carried on parallel talks about technical details.
From the beginning the negotiations were "very much an up and down road," said a US official, because there were a lot of moving pieces that had to fit together, like a Rubik's Cube.
"We'd have a moment of hope, and about an hour later you wondered whether you were going to be getting on an airplane the next minute," said the official.
"We've had moments where we said very directly to Iran; maybe you just can't get there, we can't find the place and we aren't going to be able to make it happen."
The plane was prepared for departure three times as the 31 March deadline came and went and the tension built.
The complexity and pace of the negotiations increased with the arrival of foreign ministers from Iran's other negotiating partners: Russia, China, Britain, France and Germany, known as the P5+1, who broadly supported the American approach but brought their own national objectives and viewpoints.
By the time the deadline arrived the outlines of a framework were coming together, but there were still very difficult details to resolve.
In a secure video conference the US President Barack Obama, who had amassed a knowledge almost as detailed as that of the negotiators, told them to keep going.
There followed 48 hours of virtually non-stop negotiations.
The final marathon round began at 21:00 on Wednesday evening and lasted until 06:00 on Thursday morning.
A small core of negotiators led by Mr Kerry and Mr Zarif "took issue after issue and tried to bang through solutions," aided by creative solutions from Mr Moniz and Mr Salahi, said a US official.
Experts were called in to check details with Washington, with laboratories, and with lawyers.
Passions ran high. Mr Zarif lost his temper, as did Mr Kerry, who by this time had clocked more hours negotiating at a single site on a single issue than any of his predecessors since the 1978 Camp David Accord with Egypt and Israel.
'No need to spin'
By late Thursday morning after a break to clear heads and get an hour's sleep, it became apparent to the Americans that they could probably "pull this thing together".
The sense of momentum ironed out final glitches with P5+1 ministers and "everyone came on board".
Throughout the process the two most intractable issues remained the lifting of UN sanctions and the constraints on Iran's nuclear research and development programme, particularly in the final years of an agreement.
"We basically closed out (the R&D) at 06:00 and that's not because we got up early," one US official joked with relief on Thursday, after the overnight session.
There were trade-offs. The Iranians agreed to stop uranium enrichment in the underground and previously secret nuclear facility at Fordo, the Americans agreed not to shut it down.
"Having even one centrifuge open in Fordo is hard," acknowledged a US official.
"Even if it's not a uranium centrifuge. Just optically, having centrifuges in Fordo."
"Optics" went into play immediately. The Americans released a fact sheet describing details of what had been agreed.
"There is no need to spin," Mr Zarif fired back on Twitter.
Senior US officials said both sides understood they would have different narratives, but wouldn't contradict each other.
They knew Mr Zarif would present the framework agreement as one that "enables Iran the ability to access peaceful nuclear energy," they said.
The Americans would describe it as a deal that "cuts off Iran's pathways to a nuclear weapon".
Both will have difficulty selling it - Mr Zarif to hardliners in the military and government, Mr Kerry to a sceptical congress, and Middle East allies Israel and Saudi Arabia, who worry about empowering Iran and leaving it with a nuclear infrastructure.
There are still very tough negotiations ahead on the practical details to flesh out the framework. And the conflicts in the Middle East could shape the environment of the talks and ultimately threaten them.
"It's not only the politics in each of our countries, but whether things align politically at the same time so that there's enough space to get an agreement," said a US official.