An 11th hour deal that paved the way for NATO hopefuls Sweden and Finland to soon become members was the result of weeks of political wrestling across European capitals and calibrated U.S. involvement. But moments before a deal was struck, it still looked like it was going nowhere.
After two hours of intense discussions on Tuesday before a NATO summit in Madrid, the leaders still struggled to bridge certain sticking points, with the parties repeating in frustration their existing stances, Finland's Foreign Minister Pekka Haavisto told Reuters in an interview.
"And then we had a coffee break and as always, during the coffee break, great ideas come up and then in the end, towards the end of the meeting, it was easier to come to the conclusion," Haavisto said.
So unexpected was the breakthrough, when it came, that it appeared to catch even summit officials unprepared.
Reporters were called in to witness a signing ceremony, but were not told who would be appearing or why.
Moments later the leaders of Turkey, Sweden and Finland, along with NATO Secretary-General Jens Stoltenberg, stood side-by-side as their foreign ministers signed a document. Turkish officials broke into applause, but still no-one explained to journalists what they were witnessing.
In fact, the document was a memorandum that ended a weeks-long drama.
BREAKING THE DEADLOCK
NATO had been taken by surprise in May, when Turkey announced its security demands of Finland and Sweden and put a block on a membership process most allies had thought was a formality.
There followed weeks of back and forth, led by Stoltenberg, working to avert what could have been an embarrassing deadlock for NATO as it tries to display unity in the face of Russia's invasion of Ukraine.
That process led to an important breakthrough at technical talks held in Brussels on Monday between senior officials from Turkey, Sweden and Finland.
But a compromise on several key issues - such as Sweden and Finland giving clear assurances about the steps the would take on suspected Kurdish militants that Ankara considers terrorists - were not struck until the last minute, Turkish, U.S. and NATO officials, who all spoke on the condition of anonymity, said.
A major difficulty was on something very basic - how countries defined terrorism.
"Turkey has their own definition about terrorism and terrorist groups and we couldn't agree on that definition," Haavisto said. "In the end, we could separate those issues in the statement."
Stoltenberg was particularly instrumental and encouraged the Turks to continue negotiations, while also pushing the two Nordic countries to agree to stronger commitments that Ankara sought, several sources familiar with the talks said.
"A good amount of progress was made in Brussels but a few key topics were left to be decided by the leaders themselves," a Turkish official said.
The two Nordic nations pledged not to support groups that Ankara deems terrorists and committed to prevent activities of the militant Kurdistan Workers Party (PKK) and its affiliates, the text of the deal said.
Notably, the statement said Finland and Sweden would not support the Syrian Kurdish YPG militia.
Turkey's Western allies designate the PKK as a terrorist group but not the YPG, which Ankara says is a PKK affiliate but is also a key element of the Kurdish-led coalition that the United States largely relied on to fight Islamic State.
The two Nordic countries have also pledged to address Turkey's pending extradition requests "expeditiously and thoroughly", while lifting their restrictions on selling weapons to Turkey.
APPLAUSE BEFORE DINNER
When the crisis blew up in May, analysts speculated that a gesture from the United States, perhaps even expediting the sale of F-16 fighter jets that Ankara wants, could help resolve the impasse.
But Washington has repeatedly said this was not a bilateral issue with Ankara and made an effort to remain on the sidelines.
That was a deliberate strategy, a senior U.S. administration official told reporters on Tuesday after the deal was announced, to avoid Washington becoming a party to the talks that Ankara could have made demands to.
Instead, U.S. President Joe Biden made a special effort to "choose his moments selectively" to help the parties across the finish line, the official said.
"The Finns and Swedes were very focused on deploying the president at the moment they thought most important," the U.S. official said, adding that a phone call between Biden and Turkish President Tayyip Erdogan materialised after the two Nordic countries asked Biden to reach out to Ankara.
Following the call, Erdogan departed for Madrid.
The relief was palpable for everyone, including other NATO ministers having dinner in Madrid.
"When I, with (Swedish Foreign Minister) Ann Linde, arrived to the dinner of NATO ministers, we got a big applause there and I think everybody was quite relieved that this issue was solved and they can concentrate on other issues," Haavisto said.
(Reporting by Humeyra Pamuk, Additional reporting by Tuvan Gumrukcu in Ankara, editing by Robin Emmott and Alex Richardson)