Officials had been at an impasse over an increasingly isolationist United States and Trump's climate change and trade policies for most of the summit, and Merkel made it clear the United States had made talks difficult.
"Unfortunately -- and I deplore this -- the United States of America left the climate agreement, or rather announced their intention of doing this," Merkel said as she closed the summit and presented a G20 declaration.
She said the other 19 members of the G20, which includes the European Union, agreed that the Paris climate accord was irreversible and that they remained committed to it.
Trump faced global outrage last month when he announced he would withdraw the United States from the agreement, which obliges countries to reduce their carbon emissions to ward off catastrophic global warming.
The G20 declaration noted the US withdrawal from the accord but said the country affirmed its "strong commitment to an approach that lowers emissions while supporting economic growth and improving energy security needs."
After the summit, Russian President Vladimir Putin called climate change a "major issue" and said Merkel had reached a "good compromise."
"Although the US will withdraw, they are nevertheless still prepared to carry on now (with) discussions on this subject. It seems to me this is a very positive point and can be chalked up to the successes of Angela Merkel," Putin said.
British Prime Minister Theresa May said that she was dismayed at the US climate stance and that she had urged Trump to reconsider.
And Canadian Prime Minister Justin Trudeau said that "strong economic growth and environmental protection can go hand in hand."
"This is the narrative that we have been sharing ... and was enthusiastically supported by just about everyone here at the G20."
Backtrack on trade
In her remarks, Merkel appeared to come down hard on Trump's protectionist trade policies, saying she was glad that leaders agreed that "markets need to be kept open."
"This is all about fighting protectionism and also unfair trade practices," she said.
But the declaration made concessions for "the role of legitimate trade defense instruments" in a sign that leaders had given into the United States.
Trump won the 2016 election on an "America First" platform and vowed to pull the country out of several multilateral trade deals and negotiations.
The United States has threatened to impose new tariffs on steel imports, a position that prompted European Commission President Jean-Claude Juncker to threaten the same in return, raising fears of a trade war.
Much of the attention at the G20 was on Friday's bilateral meeting between Trump and Putin.
Putin told reporters Saturday that Trump appeared to agree with Moscow's position that it did not interfere in last year's election.
"I repeat, he asked a lot of questions on this matter," Putin said at a Saturday press conference. "I answered as many as I could answer. I think he took it into consideration and agreed with it. But you should ask him what his opinion is on that."
On Friday, a senior administration official told CNN that Trump did not accept Putin's claim of noninterference in the US election.
Regarding his personal relationship with Trump, the Russian President said, "I think it was established. I don't know how this will sound, but I'll tell you how I see it. TV Trump is very different from the real person; he is absolutely specific, absolutely adequate in his perception of the dialogue partner. He analyzes things quickly, replies to the raised questions or new elements of the conversation. So I think if our future relations will unfold the same way as our meeting yesterday, there is every reason to believe that we can restore, at least partially, the level of cooperation we need."
The G20 summit has been marked by protests
against capitalism, globalization, climate change and the concentration of power among the 20 nations in the group. They have been violent at times.
The Hamburg police said that more than 200 police officers have been injured and that 114 people have been arrested. Another 89 were taken into temporary custody. It was not clear how many protesters were injured. Around 1,000 police officers arrived in Hamburg to support security forces.
With Trump aboard, Air Force One departed from Germany and was expected to arrive at Joint Base Andrews outside Washington on Saturday evening.
In a declaration issued at the end of the G20 summit, the group announced that Saudi Arabia will host the conference in 2020. Argentina will host the 2018 G20 and Japan the 2019 event, according to the declaration.