Erdogan's threat brought further disarray to a summit that was marred by bilateral quarrels and strife over climate protection and trade.
And in one of the weekend's more bizarre scenes, Trump raised eyebrows by leaving a discussion and letting his daughter Ivanka take his place.
In a departure from final summit declarations that tend to outline consensus on issues that range from fighting terrorism to financial governance, the extraordinary conclusion this year spelt out differences on core issues.
It acknowledged Trump's decision to take the United States out of the 2015 Paris deal and clearly stated Washington's wish to continue using and selling fossil fuels that are a main driver of global warming.
The declaration also stated for the first time the right of countries to protect their markets with "legitimate trade defence instruments" -- wording that essentially gives Trump wiggle room to push on with his "America First" policy.
The nationalistic stance has set him on collision course with many of America's allies, who warned Trump against an isolationist path and starting a trade war.
"Where there is no consensus, the communique spelt out the discord," said host Chancellor Angela Merkel.
- 'Problem' with Paris deal -
But with Trump determinedly leading the US out of the climate accord ratified by 153 countries, Erdogan said he was leaning towards not completing the ratification process.
"After that step taken by America, the position that we adopt is in the direction of not passing it in parliament," Erdogan said.
He also suggested some other, unidentified G20 countries had a "problem" with the agreement.
Thomas Bernes from the think-tank Centre for International Governance Innovation described the final declaration as a "masquerade".
"When compared to the G20 dynamic since the London summit in 2009, it's a step back: a clear signal against protectionism to fight the financial crisis becomes a mixed signal."
- Trail of destruction -
If the meetings within the tightly secured venue were anything but harmonious, outside chaos and violence gripped Germany's second city.
Ten minutes' walk from the summit, charred road barricades, trashed shops, debris and shattered glass bore testimony to an anarchic Friday night of street clashes between protesters and police, when commandos chased militants who hurled rocks from rooftops.
The clashes blocked US First Lady Melania Trump at her residence on Friday, forcing G20 organisers to completely alter a programme for spouses of visiting leaders.
On Saturday, thousands of anti-riot cops were again on guard, as helicopters hovered overhead, with tens of thousands of demonstrators on the march.
Fresh clashes erupted early Sunday in the streets of Hamburg following the end of the G20 summit, with protesters setting fire to a number of vehicles and police reporting more officers injured and more arrests.
- Trump vs. Putin -
Within the summit walls, world leaders were dancing a delicate diplomatic waltz, with discord not only dogging the main G20 conferences, but also adding tension to bilateral asides.
Host Merkel herself admitted that "deep differences" remain with Erdogan after they met on the sidelines of the summit.
But it was Trump's first head-to-head with Russia's leader President Vladimir Putin that stole the show.
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 meeting that ran for two hours and 15 minutes, 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" while Putin gave an upbeat assessment of what it meant for future ties.
"There is every reason to believe that we will be able to at least partially re-establish the level of cooperation that we need," Putin said.
After scoring at his Russian encounter, Trump turned to another thorny meeting, this time with Chinese President Xi Jinping.
North Korea's first intercontinental ballistic missile test announced this week was the key issue, with Trump warning Thursday that Pyongyang's military sabre-rattling would bear "consequences".
Entering into talks, Trump told his Chinese counterpart that "something has to be done" on North Korea.
In a summit with its fair share of odd and awkward moments, it was Ivanka's appearance at one discussion alongside Xi, Merkel and Erdogan that caused the biggest stir.
Historian Anne Applebaum took to Twitter to denounce what she described "an unelected, unqualified, unprepared New York socialite" being seen as "the best person to represent American national interests."
Merkel though sought to play down the case, saying that it is "in line with what other delegations do".
-----------------------------------------------------------------------------------------------------------------------
And in one of the weekend's more bizarre scenes, Trump raised eyebrows by leaving a discussion and letting his daughter Ivanka take his place.
In a departure from final summit declarations that tend to outline consensus on issues that range from fighting terrorism to financial governance, the extraordinary conclusion this year spelt out differences on core issues.
It acknowledged Trump's decision to take the United States out of the 2015 Paris deal and clearly stated Washington's wish to continue using and selling fossil fuels that are a main driver of global warming.
The declaration also stated for the first time the right of countries to protect their markets with "legitimate trade defence instruments" -- wording that essentially gives Trump wiggle room to push on with his "America First" policy.
The nationalistic stance has set him on collision course with many of America's allies, who warned Trump against an isolationist path and starting a trade war.
"Where there is no consensus, the communique spelt out the discord," said host Chancellor Angela Merkel.
- 'Problem' with Paris deal -
But with Trump determinedly leading the US out of the climate accord ratified by 153 countries, Erdogan said he was leaning towards not completing the ratification process.
"After that step taken by America, the position that we adopt is in the direction of not passing it in parliament," Erdogan said.
He also suggested some other, unidentified G20 countries had a "problem" with the agreement.
Thomas Bernes from the think-tank Centre for International Governance Innovation described the final declaration as a "masquerade".
"When compared to the G20 dynamic since the London summit in 2009, it's a step back: a clear signal against protectionism to fight the financial crisis becomes a mixed signal."
- Trail of destruction -
If the meetings within the tightly secured venue were anything but harmonious, outside chaos and violence gripped Germany's second city.
Ten minutes' walk from the summit, charred road barricades, trashed shops, debris and shattered glass bore testimony to an anarchic Friday night of street clashes between protesters and police, when commandos chased militants who hurled rocks from rooftops.
The clashes blocked US First Lady Melania Trump at her residence on Friday, forcing G20 organisers to completely alter a programme for spouses of visiting leaders.
On Saturday, thousands of anti-riot cops were again on guard, as helicopters hovered overhead, with tens of thousands of demonstrators on the march.
Fresh clashes erupted early Sunday in the streets of Hamburg following the end of the G20 summit, with protesters setting fire to a number of vehicles and police reporting more officers injured and more arrests.
- Trump vs. Putin -
Within the summit walls, world leaders were dancing a delicate diplomatic waltz, with discord not only dogging the main G20 conferences, but also adding tension to bilateral asides.
Host Merkel herself admitted that "deep differences" remain with Erdogan after they met on the sidelines of the summit.
But it was Trump's first head-to-head with Russia's leader President Vladimir Putin that stole the show.
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 meeting that ran for two hours and 15 minutes, 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" while Putin gave an upbeat assessment of what it meant for future ties.
"There is every reason to believe that we will be able to at least partially re-establish the level of cooperation that we need," Putin said.
After scoring at his Russian encounter, Trump turned to another thorny meeting, this time with Chinese President Xi Jinping.
North Korea's first intercontinental ballistic missile test announced this week was the key issue, with Trump warning Thursday that Pyongyang's military sabre-rattling would bear "consequences".
Entering into talks, Trump told his Chinese counterpart that "something has to be done" on North Korea.
In a summit with its fair share of odd and awkward moments, it was Ivanka's appearance at one discussion alongside Xi, Merkel and Erdogan that caused the biggest stir.
Historian Anne Applebaum took to Twitter to denounce what she described "an unelected, unqualified, unprepared New York socialite" being seen as "the best person to represent American national interests."
Merkel though sought to play down the case, saying that it is "in line with what other delegations do".
-----------------------------------------------------------------------------------------------------------------------