NATO leaders have set aside public insults ranging from "delinquent" to "brain dead" and "two-faced", declaring at a 70th anniversary summit they would stand together against a common threat from Russia and prepare for China's rise.
Officials insisted the summit was a success but the meeting began and ended in acrimony.
US President Donald Trump arrived declaring the French president "nasty" and left calling Canada's prime minister "two-faced" for mocking him on a hot mic.
"We have been able to overcome our disagreements and continue to deliver on our core tasks to protect and defend each other," NATO's ever-optimistic Secretary-General Jens Stoltenberg told a news conference on Wednesday.
In a joint declaration, the alliance's 29 leaders said: "Russia's aggressive actions constitute a threat to Euro-Atlantic security; terrorism in all its forms and manifestations remains a persistent threat to us all."
The half-day summit at a golf resort on the outskirts of London was always going to be tricky, with officials hoping to avoid bust-ups that burst forth at their meeting last year when Trump complained about allies failing to bear the financial burden of collective security.
This year's meeting was made even more difficult by Erdogan, who launched an incursion into Syria and bought Russian missiles against the objections of his allies, and by French President Emmanuel Macron, who had described the alliance's strategy as brain dead in an interview last month.
In public it seemed to go worse than expected, beginning on Tuesday when Trump called Macron's remarks "very, very nasty" and described allies who spend too little on defence as "delinquents" - a term officials said Trump used again on Wednesday behind closed doors during the summit itself.
At a Buckingham Palace reception on Tuesday evening, Canada's Justin Trudeau was caught on camera with Macron, Britain's Boris Johnson and Mark Rutte of the Netherlands apparently laughing at Trump's long press appearances.
Trump said Trudeau was upset because he had called him out for not meeting his 2 per cent of national output contribution to NATO's costs. "He's two-faced," Trump said of his North American neighbour.
But in a news conference after the summit, Trudeau downplayed his comments, which he said had been referring to Trump's unexpected announcement that the next G7 summit will take place at Camp David and he had meant no offence.
"We had a great meeting yesterday between me and the president," he said.
By the time the summit wound up on Wednesday, Trump had decided not to hold a final press conference, saying he had already said enough, including commenting on Britain's upcoming election on Tuesday, despite saying he didn't want to.
Despite the spats, officials said important decisions were reached, including an agreement to ensure the security of communications, including new 5G mobile phone networks. The US wants allies to ban equipment from the world's biggest telecoms gear-maker, Chinese firm Huawei.
"I do think it's a security risk, it's a security danger," Trump said in response to a question on Huawei, although the leaders' declaration did not refer to the company by name.
"I spoke to Italy and they look like they are not going to go forward with that. I spoke to other countries, they are not going to go forward," he said of contracts with Huawei.
Macron held his ground over his earlier criticism of NATO's strategy, saying as he arrived that it was important for leaders to discuss issues in an open and forthright manner if they were to find solutions.
One of Macron's chief complaints is that Turkey, a NATO member since 1952 and a critical ally in the Middle East, has increasingly acted unilaterally, launching its incursion in Syria and buying Russian S-400 anti-aircraft missiles.