France's President Emmanuel Macron and Germany's Chancellor Angela Merkel and other world leaders, during the announcement of a trade agreement between the EU and Mercosur | Carl Court/Getty Images G20 leaders agree declaration after climate fight 19 of the 20 countries backed the Paris Agreement.

OSAKA, Japan — G20 leaders on Saturday agreed a final declaration after a fight between the EU and U.S. on climate change that risked collapsing the leaders' statement.

The text maintains a "similar" commitment to fight climate change as in previous declarations in Buenos Aires and Hamburg, German Chancellor Angela Merkel said at a press conference at the end of the summit.

Under the compromise struck at the last minute on Saturday, heads of state from 19 of the 20 countries backed the Paris Agreement, while the United States secured a carve-out under an 'agree to disagree' framework — the same solution as in previous G20s since U.S. President Donald Trump was elected.

Until Saturday morning, the G20 had been at risk of ending without a declaration, as U.S. President Donald Trump tried but failed to get other countries to join his camp and oppose the Paris Agreement.

"We've succeeded after days and nights of negotiations to have again, after all, a 19 to 1 declaration, where the 19 signatory countries of the Paris Agreement commit to the same things as we did in Buenos Aires," Merkel said. "We say that this process is 'irreversible' and we say that we have made our commitments [to cut greenhouse gas emissions] and will do a review again in 2020 to see whether we must make new commitments."

French President Emmanuel Macron slammed the United States for trying to water down the climate commitments.

"We [the G20] are increasingly disconnected from the rest of the world ... Our scientists every day remind us of our duty in matters of climate change and biodiversity, our youth every week in France and many countries remind us of our duty, while we at the G20 continue having debates on whether we can still cite the Paris Agreement."

Two senior EU negotiators said they had fought with the United States over the climate chapter until 4 a.m. on Saturday, when they decided to pause talks as they saw no way out of the deadlock.

Around 11 a.m., things started moving again as sherpas handed over the baton to heads of state, who agreed to back the '19 to 1' format.

Crucially, China backed the EU and fought to keep countries committed to the Paris Agreement. In a joint statement released Saturday morning, China and France pushed countries to stick to the climate deal.

The final communiqué will also mention trade and migration, officials said, but will stop short of denouncing "protectionism," a taboo for the U.S.

Instead, the leaders made a "clear commitment to free, fair, non-discriminatory, transparent trade" and declared that a reform of the World Trade Organization is "necessary."

"And I say this quite clearly, this is so important, because otherwise the WTO will enter a phase of inability to work, and that is why the communiqué at this point was very, very important to us," Merkel added.

In their statement, the G20 leaders will also address migration and promise to "closely" work with the U.N. and other international organizations on their migration policies, Merkel said.