Hamburg (AFP) - US President Donald Trump won key concessions on climate and trade Saturday from world leaders at the most fractious G20 summit to date, in exchange for preserving the unity of the club of major industrialised and emerging economies.

In a final statement agreed by all 20 economies, 19 members including Russia, China and the European Union acknowledged Trump's decision to go his own way on taking the US out of the 2015 Paris climate accord.

But they also accommodated Washington's wish to "work closely with other countries to help them access and use fossil fuels more cleanly and efficiently".

While renewing a key anti-protectionist pledge, the communique for the first time underlined the right of countries to protect their markets with "legitimate trade defence instruments".

Such wording gives room for Trump to push on with his "America First" policy.

Carried on a wave of public fury over deindustrialisation in vast areas of the United States, Trump had promised to "Buy American" and "Hire American".

But that stance had set him against many of America's allies, who warned Trump against an isolationist path.

Nevertheless, the wording of the final agreement marked the group of top economies' decision to finally close ranks despite bitter differences.

- Trail of destruction -

Just behind the tightly secured G20 summit venue, charred road barricades, trashed shops and stones, debris and shattered glass bore testimony to an anarchic night, when police commandoes with semi-automatic weapons detained militants who hurled rocks from rooftops.

The clashes had blocked US First Lady Melania Trump at her residence on Friday, forcing her to miss a tour of Hamburg harbour, and for G20 organisers to completely alter a programme for spouses of visiting leaders.

On Saturday, thousands of anti-riot cops were on standby and helicopters hovered overhead, as some 70,000 people were on the march again, according to organisers.

- Trump vs. Putin -

Story continues

Within the summit walls, meetings have also been anything but harmonious.

All eyes were also on Trump's diplomatic waltz during the billionaire's first outing to the summit.

His most eagerly awaited encounter was a head-to-head with Russia's strongman President Vladimir Putin -- their first -- which lasted two and a quarter hours on Friday.

A day after Trump slammed Moscow's actions in Ukraine and Syria, the two men had a "robust and lengthy exchange" about allegations of Russian meddling in the 2016 US election, Secretary of State Rex Tillerson said.

But Tillerson, who was present at the marathon meeting, also said the two alpha-male leaders "connected very quickly" with "very clear positive chemistry".

Trump said Saturday that the tete-a-tete was "tremendous".

Further driving a wedge between the UK and the European Union, Trump met Saturday with British Prime Minister Theresa May and said he was looking forward to a "very powerful" trade deal "very, very quickly".

His comments came despite the EU warning London against negotiating any separate agreement before Britain's divorce from the bloc is complete.

But Trump faced another thorny meeting later, when he is due to hold talks with Chinese President Xi Jinping.

North Korea's first inter-continental ballistic missile test is expected to top the discussions, with Trump warning Thursday that Pyongyang's military sabre-rattling would bear "consequences".

Trump had also said he is considering a "severe" response to its "very, very bad behaviour".

Ahead of the talks with Xi, Tillerson said the US would continue to press China to do more to rein in Pyongyang.

"Our engagement is unchanged with China and our expectations are unchanged. We have not given up hope," he added.