The G20 leaders have reached agreement on a communique after their two-day summit on most points but climate remains a thorny issue.
World leaders meeting for a summit in Germany have agreed on every aspect of a joint statement apart from the section on climate where the US is pushing for a reference to fossil fuels, European Union officials say.
The officials say aides had worked until 2am on Saturday to finalise a communique for the Group of 20, overcoming differences on trade after US 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 US 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 US 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 US election but agreed to focus on future ties rather than dwell on the past, a result that was sharply criticised by leading Democrats in the US 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 change policy proved a sticking point, with the US 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 US from the landmark Paris climate accord aimed at combating climate change, and reaffirmed the commitment of the other 19 members to the agreement.
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.
Police said 200 officers had been injured, 134 protesters temporarily detained and another 100 taken into custody.