LAUSANNE, Switzerland (Reuters) - When Russian Foreign Minister Sergei Lavrov announced on Wednesday that a framework nuclear deal had been reached between Iran and major world powers, the French delegation to the talks thought it was an April Fool's Day joke.
In the end, a deal was formally announced a day later. But after eight days of talking, with a Tuesday midnight deadline already history, it had gone to the wire and beyond.
Before the delegations paused to rest briefly as the sun came up over Lake Geneva on Thursday, U.S. Secretary of State John Kerry met repeatedly during the night with Iranian Foreign Minister Mohammad Javed Zarif, Laurent Fabius of France and Germany's Frank Walter Steinmeier.
Pressure from outside had been intense. The White House said Washington was prepared to walk away if necessary, while the Iranian delegation had to constantly consult with Tehran.
In an indication of how difficult the discussions had become, Fabius left the talks on Tuesday in the middle of the night, ostensibly to attend a cabinet meeting. But diplomats said the negotiations had become too complicated and it was "not for him to haggle over centrifuges".
The talks were held in Lausanne's lakeside Beau Rivage Palace hotel, where a cocktail can cost more than $70. Coco Chanel's dog is buried in the grounds and at times it looked as if hopes of a nuclear deal might be interred there too.
But by Tuesday it started to be clear the deal would probably come together. It took two more days to work out, due to what negotiators said were the two main sticking points – U.N. sanctions and centrifuge research and development work.
Senior U.S. officials described how they avoided putting things on paper. They were trying to come up with a public statement and an annex to the agreement that would have more numerical details than the public statement.
"They don’t like to get paper, because if they get paper they got to take it back to Tehran," one official said.
So they used a dry-erase whiteboard to do their drafting. All the delegations would bring their own pieces of paper with their ideas and then they would use the white board to come up with a joint outline for a deal. As things changed, they would erase the board and put new details on it.
One negotiator accidentally used a permanent marker on the white board to add one of the more confidential numbers under discussion. When the negotiating session ended, officials were unable to erase the figure and had to vigorously scrub it off.
The give and take in the negotiating room wasn't simple horse trading, on of the U.S. officials said. The whole deal was like a Rubik's cube – each time one element changed, others had to change with it. But as with any negotiation, the United States had to give up some things.
One concession the United States didn't want to make but did was to let Iran have centrifuges at the underground Fordow site.
“We gave some things that are hard for us. Having even one centrifuge at Fordow is hard,” the first senior U.S. official said, referring to an underground site that the Iranians had hidden until its existence was revealed by the United States, Britain and France in 2009.
But with the framework announced, more hard work lies ahead before June 30, the date set for a final deal.
Senior Iranian officials began thinking about the need to reopen negotiations with Washington in late 2012 after they began to see the crippling impact of Western sanctions imposed because of Tehran's nuclear ambitions.
Iranian officials close to the supreme leader, Ayatollah Ali Khamenei, had grown tired of former President Mahmoud Ahmadinejad's confrontational approach to Israel and the West, which had galvanized opposition to Iran.
A few months before Iran's June 2013 presidential election, in a secret meeting between Khamenei and a small group of top officials, the issue of who should succeed Ahmadinejad was discussed. They all agreed on Rouhani.
"Rouhani's mandate was to improve the economy, hit by the sanctions and Ahmadinejad's economic mismanagement," an Iranian official told Reuters.
After Rouhani was elected, Foreign Minister Zarif, who knew a number of American officials including Secretary of State John Kerry, approached them seeking to pave the way towards ending the nuclear standoff, the official said.
Khamenei was suspicious of the Americans and not optimistic about talking with them. But in the interests of the economy, he backed negotiations.
Immediately after winning a vote of confidence in parliament, Rouhani met Kerry in September 2013, followed by the Iranian president's historic phone call with Barack Obama - the first such conversation between Iranian and U.S. presidents since ties were severed three decades ago.
After secret meetings between Iranian and U.S. officials, sometimes involving Omani intermediaries, the two sides agreed in September 2013 to relaunch the talks process that began in 2006 but stalled when it became clear that Ahmadinejad could not deliver a deal that Iran's hard-liners could accept.
Ahmadinejad's diatribes against the West had persuaded the European Union to join Washington in imposing sanctions on Iran, and the leadership in Tehran eventually opted for negotiations.
A U.S. official said sanctions meant "it was time to talk".
In a year and a half of talks in Geneva, Vienna, Lausanne, New York and elsewhere, U.S.-Iranian relations underwent a subtle shift. But despite increased cordiality between Iranian and U.S. officials, relations overall are still fraught.
Zarif was summoned before parliament in January after images of him and Kerry strolling together by Lake Geneva provoked outcry among hard-liners.
Although Rouhani and Zarif wanted a deal, it was not always clear that Khamenei did too.
The first sign things were going wrong came last July, when he blindsided Zarif by demanding huge increases in nuclear centrifuge numbers.
There had earlier been indications that the Iranian delegation wanted to compromise.
But after the possibility of a compromise vanished and a four-month extension was agreed until Nov. 24, which Western officials hoped would allow Rouhani and Zarif to persuade hardliners in Tehran that an agreement could end sanctions.
But months of meetings between Iranian and American negotiators, including former Deputy Secretary of State Bill Burns, who began secret talks with Iran in 2013 to lay the groundwork for the current negotiations, and Under Secretary of State Wendy Sherman, who has led the U.S. delegations in Geneva and Vienna, failed find a compromise.
They also failed to break the deadlock in November, agreeing another extension until June 30, with the understanding that the parties should reach a framework agreement by the end of March.
Western officials said the Obama administration and the Rouhani government both faced uphill battles to make their case to hardliners.
For Obama, there is perhaps an awareness that the only major "deliverable" he can achieve in his final two years in office is a deal with Iran.
And in Iran, many think Kerry wanted to help Obama secure his legacy. They also point to Kerry's Iranian-American son-in-law as proof that, as one Iranian woman put it, he is "on our side".
Additional reporting by Stephanie Nebehay; Editing by Giles Elgood