World leaders meeting for a summit in Germany have agreed every aspect of a joint statement apart from the section on climate where the United States is pushing for a reference to fossil fuels, European Union officials said on Saturday.

The officials said aides had worked until 2 a.m. to finalise a communique for the Group of 20, overcoming differences on trade after U.S. officials agreed to language on fighting protectionism.

"The outcome is good. We have a communique. There is one issue left, which is on climate, but I am hopeful we can find a compromise," said one EU official, speaking on condition of anonymity. "We have all the fundamentals.

"We have a G20 communique, not a G19 communique," he added.

The section that needs to be resolved by the leaders relates to the U.S. insistence that there be a reference to fossil fuels, the official said.

With the final statement almost nailed down, the summit marked a diplomatic success for Chancellor Angela Merkel as she finessed differences with U.S. President Donald Trump, who arrived at the two-day summit isolated on a host of issues.

Trump, who on Friday found chemistry in his first face-to-face meeting with Russian President Vladimir Putin, congratulated Merkel for her stewardship of the summit.

"You have been amazing and you have done a fantastic job. Thank you very much chancellor," he said.

Trump and Putin on Friday discussed alleged Russian meddling in the U.S. election but agreed to focus on future ties rather than dwell on the past, a result that was sharply criticised by leading Democrats in Congress.

For Merkel, the summit is an opportunity to show off her diplomatic skills ahead of a federal election in September, when she is seeking a fourth term in office.

She treated the leaders to a concert at Hamburg's Elbphilharmonie on Friday night, where they listened to Beethoven while their aides began their all night slog to work out a consensus on trade that had eluded the leaders.

Trade policy has become more contentious since Trump entered the White House promising an "America First" approach.

The trade section in the statement the aides thrashed out read: "We will keep markets open noting the importance of reciprocal and mutually advantageous trade and investment frameworks and the principle of non-discrimination, and continue to fight protectionism including all unfair trade practices and recognise the role of legitimate trade defence instruments in this regard."

CLIMATE CLASH

Climate change policy proved a sticking point, with the United States pressing for inclusion of wording about which other countries had reservations.

That passage read: "... the United States of America will endeavour to work closely with other partners to help their access to and use of fossil fuels more cleanly and efficiently ..."

The climate section took note of Trump's decision last month to withdraw the United States from the landmark Paris climate accord aimed at combating climate change, and reaffirmed the commitment of the other 19 members to the agreement.

Merkel chose to host the summit in Hamburg, the port city where she was born, to send a signal about Germany's openness to the world, including its tolerance of peaceful protests.

As the leaders met on Saturday, police helicopters hovered overhead. Overnight, police clashed with anti-capitalist protesters seeking to disrupt the summit.

In the early morning, heavily armed police commandos moved in after activists had spent much of Friday attempting to wrest control of the streets from more than 15,000 police, setting fires, looting and building barricades.

The summit is being held only a few hundred metres from one of Germany's most potent symbols of left-wing resistance, a former theatre called the "Rote Flora" which was taken over by anti-capitalist squatters nearly three decades ago.

Police said 200 officers had been injured, 134 protesters temporarily detained and another 100 taken into custody.