In a stunning tweet on Monday, Iranian President Hassan Rouhani declared: "#IranDeal is the victory of diplomacy & mutual respect".
Except that it wasn`t. The latest round of ministerial negotiations between Iran and six world powers on curbing Iran`s nuclear programme were still in full swing, 17 days in, and Rouhani had jumped the gun. The tweet was deleted.
But then it reappeared, with a judicious edit. "If #IranDeal, victory of diplomacy and mutual respect ..."
It was a moment that revealed perhaps the most crucial aspect of the deal in Vienna on Tuesday: that the main protagonists, Iran and the United States, for decades the bitterest of enemies, had too much invested in the process to let it fail without a fight, and the longer the talks went on, the likelier a deal became.
One U.S. nuclear expert calculated that he had travelled 400,000 miles (643,700 km) - the distance to the moon and halfway back - since February 2014 in the search for an agreement.
Some of his colleagues were on their 18th visit to Vienna, scene of most of the talks. Unlike his big power counterparts, U.S. Secretary of State John Kerry, on crutches after breaking his leg in a cycling accident, remained in Vienna for the entire duration of the ministerial round. It was the longest period that anyone could remember an American secretary of state staying in a single foreign location in peacetime.
It was the culmination of a huge commitment that began when the pragmatist Rouhani was elected president of Iran in mid-2013.
By November of that year, an interim confidence-building deal had been agreed that gave Iran limited sanctions relief in exchange for freezing the nuclear programme that Western powers suspected to have been a cover for weapons development, something Tehran has consistently denied.
ANOTHER 17 MONTHS
It took a further painful 17 months of wrangling between Iran and the United States, France, Britain, Germany, Russia and China, including the conclusion of a "framework deal" in April that went 30 hours into overtime, to get to Vienna.
It all meant that, even after the talks had been extended for the third time past their long-forgotten June 30 deadline, Kerry and Iranian Foreign Minister Mohammad Javad Zarif remained confident of eventual success - infuriatingly so for Kerry`s European partners, who challenged him to back up his assertion that he was prepared to "walk" if necessary.
"These ****ing negotiations are not held together," complained one European diplomat. "They are going in all directions and Kerry is just sitting there saying, `I don`t care how long we stay, we need a deal and can`t put Zarif in a corner`."
When European Union foreign policy chief Federica Mogherini, coordinating the six powers, threatened to quit the talks in a meeting with Zarif on July 6, he lost his temper and yelled "Never threaten an Iranian!", according to a report by Iran`s Mehr news agency.
Zarif and Kerry, for their part, met face-to-face about 20 times in Vienna, although they, too, lost their cool at a meeting earlier the same day, their raised voices carrying into the corridors of the genteel 19th-century Palais Coburg hotel.
Both men knew that, for all their patience, they had to produce a deal that would be supported by their own leaders.
Zarif flew home to Tehran on June 28, two days before the original deadline, for consultations after Iran`s Supreme Leader, Ayatollah Ali Khamenei, set out unexpectedly tough "red lines" in a speech.
A senior U.S. official said Washington had seen this as "an indication that he would presumably return with the Supreme Leader’s guidance and the necessary authority to close a deal ... That’s ultimately what seems to have transpired."
Then, last Wednesday, U.S. President Barack Obama, under pressure from critics who accused him of giving too much ground in the quest for a deal, held a video conference with his team in Vienna in which he "essentially rejected the deal that was on the table", a White House official said.
The sticking points he named were those that diplomats in Vienna said had occupied the last hours of the talks, into the small hours of Tuesday: how long would a U.N. embargo on selling weapons and missile technology to Iran be maintained, and how quickly would sanctions be lifted - and potentially restored if Iran violated the terms of the deal?
But at the same time, he told the U.S. negotiators: "I don’t care about any particular deadline, I care about the quality of the deal," the official said.
Kerry almost certainly thought much the same. After failing to revive Israeli-Palestinian peace talks in months of dogged shuttle diplomacy early in his tenure, Iran was his chance to secure a lasting legacy.
For his part, Zarif told Kerry early this year that failure to achieve a nuclear deal would herald the demise of Rouhani, who had promised that to revive Iran`s crippled economy by ending its international isolation.
After finally sealing "the most significant multilateral nuclear agreement in two decades", former IAEA official Tariq Rauf, director of the Disarmament and Non-Proliferation Programme at the Stockholm International Peace Research Institute, said he had no doubt that Kerry and Zarif had done enough to secure a Nobel Peace Prize.
In that final session, when there was some measure of exhausted jubilation that the deal was done, Kerry choked up as he recounted how he went to war aged 22. "He couldn`t get the words out," said a U.S. official who spoke on condition of anonymity.
After a moment, Kerry, who had served in the U.S. military during the Vietnam War, went on to say he hoped the Iran deal would limit more conflicts in the future.
Everyone applauded, the official said, including the Iranians.