It was not all rows and rifts. There were moments of convivial relaxation, such as Friday night’s rendition of Beethoven’s Symphony No 9 – the official EU anthem – in Hamburg’s Elbphilharmonie concert hall. As they listened, Theresa May and her husband, Philip, sat close to Donald and Melania Trump, and not far from the new French power couple, Emmanuel and Brigitte Macron. Afterwards the G20 leaders sat down to turbot, buttered spinach, beef and glazed potato wedges, and a fruit dessert.

But the music night was a rare cultural oasis in the gruelling timetable of the Hamburg G20. The two-day summit, which ended on Saturday, had been pitched as one of the most tense get-togethers of world leaders in many years. It did not disappoint, with America’s president inevitably at the heart of much of the action.

Friday’s much-anticipated head-to-head with Vladimir Putin went well, in the judgment of the White House, with talks extending amicably well beyond two hours. But Trump, according to one western diplomat, sat with arms folded and a “face like thunder” as he listened to China’s President Xi Jinping speak on trade during a working lunch for leaders. Disagreements between the countries on the question of steel dumping have not been resolved by this latest encounter. There was also some bemusement when Trump’s daughter, Ivanka, stood in for the president when, in the words of a subsequent White House statement, he “had to step out”.

As anticipated, the big bone of contention was Trump’s decision to withdraw America from the Paris climate agreement. This was still being argued over throughout Saturday, as leaders entered their final sessions. The outcome was a 19-1 standoff pitting the US against the rest of the world, as a joint summit statement noted the US withdrawal from the agreement, but leaders of the 19 other G20 nations agreed that the accord was “irreversible”.

Macron, the French president, set the increasingly robust tone, snapping at one point that the whole world knew it was a mistake for the US to withdraw from the Paris agreement. Sources said tensions ran particularly high between French and US officials, who also clashed over an attempt by Trump’s team to insert a clause into the final communique saying the US would support other countries in accessing clean “fossil fuels”. At one point talks broke up for two hours while the US and France argued over the climate section, according to a source.

The German chancellor, Angela Merkel, Theresa May, Donald Trump and the Canadian prime minister, Justin Trudeau, at the summit. Photograph: Carlos Barria/Reuters

In the final hours of the two-day session, Macron asked May and the Australian prime minister, Malcolm Turnbull, to step out of a working session with Trump to discuss climate change. “There was concern that not being able to agree the language on Paris could hold up the whole summit communique,” said a diplomatic source.

May – who was on a mission to woo the US president on behalf of Brexit Britain – exerted her own pressure on Trump over free trade, insisting that the G20 must reject protectionism if it is to help raise citizens’ living standards.

In a separate session on the same subject, Macron pulled out his mobile phone and tried to lecture his US counterpart about the fact that trade is a multilateral issue, not a two-way street, arguing that the device might have been built in the US, but with Chinese parts. Sources said Trump had stepped out of the room during the key sessions, and Macron had quipped that the US president was never there when he wanted to address him.

One G20 veteran, Tom Bernes, who has held senior positions at the IMF and in the Canadian government, said leaders and officials usually arrived at the summits in a “collaborative spirit”.

“Sometimes you had a difficult brief, but there was a sense of collaboration,” said Bernes, who is a fellow of the Centre for International Governance Innovation. “But this time there is the America-first philosophy. Trump’s attitude is: ‘It is my way or the highway.’”

His comments underlined the impression that the US president was a somewhat isolated figure during the deliberations in Hamburg.

Many of the most difficult conversations took place in a nondescript room near the leaders’ hall, where each country sent its appointed sherpa to negotiate the G20 communique wording. Their discussions stretched until 3am on the final night, amid clashes over trade and climate change. As tensions rose, dinners were cancelled and replaced with ham sandwiches and espresso. One source said the US had come to the table “very late and very aggressively – fighting on all fronts”.

Shinzō Abe, the prime minister of Japan, with Theresa May in Hamburg. Photograph: Matt Cardy/PA

One source said UK officials had acted as go-betweens during the disagreement between the US and China over alleged over-production of steel, a running sore in talks. At one point there had been a “30-minute row whether something should be ‘noted’ or ‘acknowledged”.

For May, wins were seen as getting action on disruption of terrorism-financing into the communique, and collaborating with the EU team on free trade. For the prime minister, this G20 meeting was all about signalling a desire to reach beyond the shores of the EU after Brexit, with trade at the centre of bilaterals with India’s Narendra Modi, Japan’s Shinzō Abe, Xi, and – of course – Trump.

May’s 50-minute session with the US president was judged a success by British aides, with May reportedly delighted by Trump’s suggestion that a post-Brexit trade deal could be drummed up “very, very quickly”. In a longer-than-expected meeting with a “very good atmosphere”, May did not raise the US president’s demeaning comments about the London mayor, Sadiq Khan, nor Trump’s decision to withdraw from the Paris climate deal, despite signalling in advance that she would.

However, an official later confirmed that May had raised America’s withdrawal from the Paris agreement as the pair continued to talk one-on-one at the G20 working session on Africa.

The German host, Angela Merkel, had prioritised the building of a partnership with African countries aimed at building up economies in order to reduce dependence on aid and address the migration crisis. Charities and campaigners remained unimpressed with the largely rhetorical outcome.

Friederike Röder, G20 director of the charity, said it was the right approach but the leaders had fallen short. “The African population is going to double by 2050 – in less than 50 years more young people in Africa than in all G20 countries, including China and India,” she said.

“We need action on education, employment and empowerment. We need a partnership to tackle the root causes of enforced migration.

“We fear this G20 won’t deliver on the ambition. They called for a partnership but then didn’t turn up for the deal making.”