HAMBURG, Germany — World leaders struck a compromise on Saturday to move forward collectively on climate change without the United States, declaring the Paris accord “irreversible” while acknowledging President Trump’s decision to withdraw from the agreement.

In a final communiqué at the conclusion of the Group of 20 summit meeting in Hamburg, Germany, the nations took “note” of Mr. Trump’s decision to abandon the pact and “immediately cease” efforts to enact former President Barack Obama’s pledge of curbing greenhouse gas emissions 26 to 28 percent below 2005 levels by 2025.

But the other 19 members of the group broke explicitly with Mr. Trump in their embrace of the international deal, signing off on a detailed policy blueprint outlining how their countries could meet their goals in the pact.

The statement and the adoption of the G20 Climate and Energy Action Plan for Growth ended three days of intense negotiations over how to characterize the world’s response to Mr. Trump’s decision to pull out of the Paris climate agreement, and it came as this year’s meeting of major world economies here laid bare the stark divide between the United States and the rest.

“This is a clear indication that the U.S. has isolated itself on climate change once again, and is falling back while all other major economies step up and compete in the clean energy marketplace created by the Paris Agreement estimated to be worth over 20 trillion dollars,” said Andrew Light, a senior climate change adviser at the State Department under Mr. Obama.

Differences between the United States and other nations on climate, trade and migration made for a tricky summit meeting, which unfolded amid large protests that sometimes turned violent, with several injured and demonstrators setting fire to cars and looting in the streets of the German city.

“Nothing’s easy,” Mr. Trump said of the gathering on Saturday as he complimented its host, Chancellor Angela Merkel of Germany, who has toiled to bridge the gap between the United States and other nations, for handling the challenge “so professionally.”

Hours later, at the start of a high-stakes meeting with President Xi Jinping of China, Mr. Trump vowed to confront the threat posed by North Korea “one way or the other,” and said he appreciated the Chinese leader’s efforts to respond to Pyongyang’s latest provocations.

“It may take longer than I’d like, it may take longer that you’d like, but there will be success in the end, one way or the other,” Mr. Trump said. “Something has to be done about it.”

As he sought to build a consensus among Asian leaders about how best to deal with North Korea, Mr. Trump also held a separate meeting with Prime Minister Shinzo Abe of Japan. The two leaders were tackling “the problem and menace of North Korea,” Mr. Trump said.

The wording on climate change in the communiqué represented a victory for Ms. Merkel, who played a major role in forging compromise language after France raised objections.

In most other respects, though, the summit meeting had to be a bitter disappointment for the chancellor. When the meeting was first planned for Hamburg, Ms. Merkel’s birthplace, she would have reasonably expected Hillary Clinton, a likely political partner, to be the American president, and she had expected the event to be a strong part of her re-election campaign for a fourth term, with voting in September.

It has also been about efforts by most of the rest of the world to cajole the American president into softening his stances on global trade and the climate, with Ms. Merkel in a secondary role, trying to come up with compromises.

Her standing has also suffered as Germans have been shocked by violent protests by a small bloc of anarchists who saw the G-20 as a perfect platform for their rejection of capitalism and order.

The atmosphere around Hamburg has been that of an armed camp, hardly welcoming, with 20,000 police officers asking for further reinforcements to try to protect the various leaders. So far, 213 police officers have been injured, and 43 people have been arrested and 96 more detained.

Ms. Merkel expressly backed the 100,000 or so peaceful demonstrators who massed here in recent days and were marching on Saturday. She may have been hoping to show authoritarian leaders like Mr. Putin and Turkey’s president, Recep Tayyip Erdogan, how to tolerate protests in a democracy. If so, she and the security forces failed, losing control in parts of the city. Ms. Merkel was born in Hamburg in 1954, weeks before her parents moved east to Communist Germany.

This was always going to be risky for Ms. Merkel, and Mr. Trump’s presence only intensified what were widely anticipated to be widespread and sometimes violent protests against globalization, even though Mr. Trump is a sharp critic of globalization.

Whether the criticism of holding the summit meeting here will hurt Ms. Merkel in the September elections is not clear. Her popular conservative finance minister, Wolfgang Schäuble, appeared on national television on Friday strongly defending the decision. Only large cities like Hamburg, a picturesque Hanseatic port, have the infrastructure to host the thousands of leaders, delegates, journalists and lobbyists who gather at a G-20 meeting, he said.

And some diplomatic work was done at the meeting, even beyond Mr. Trump’s meetings and his hyperbolic praise — regardless of his private views — of every leader he meets, including Ms. Merkel. (“You have been amazing and you have done a fantastic job.”)

Working overnight, diplomats first agreed on a common text on trade, with a nod toward Mr. Trump’s “America First” demands for restrictions on unfair trade, but they had great difficulty on climate, with the Americans demanding a reference to the use of fossil fuels.

President Emmanuel Macron of France said he would continue to press Mr. Trump on climate and would hold a follow-up summit meeting in Paris in December to move the Paris deal forward.

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 nondiscrimination, and continue to fight protectionism including all unfair trade practices and recognize the role of legitimate trade defense instruments in this regard.”

In his meeting with China’s leader, Mr. Trump said that “many things have happened that have led to trade imbalances” and that he wanted a new arrangement that is “equitable” and “reciprocal.”

The climate section is more of a dodge. It takes note of the American decision to withdraw from the Paris accord and says the other countries regard the deal as “irreversible.” Yet it subtly left open the possibility that the United States could someday come back into the pact, specifying that the country is putting the brakes on its “current” emissions pledge.

It then nods toward fossil fuels, saying: “The United States of America states it will endeavor to work closely with other countries to help them access and use fossil fuels more cleanly and efficiently.”

Mr. Trump met with Prime Minister Theresa May of Britain on Saturday, trying to fortify her delicate political fortunes. He said that they had had “tremendous talks” on trade and were working on a “very powerful” trade deal for a post-“Brexit” Britain that could be completed “very, very quickly.”

It is not clear what Mr. Trump meant, since the two sides cannot sign such an agreement until after Britain leaves the European Union, in March 2019 at the soonest.

Mr. Trump, who returned to Washington on Saturday night, also confirmed that he would eventually make a state visit to Britain, but the dates continue to be unclear.

Also on Saturday, American officials said that Mr. Trump would order the State Department to redirect $50 million from its foreign-aid budget to a new international public-private partnership to aid midsize businesses run by women, a group that his daughter Ivanka Trump helped create.

The partnership aims to “help women in developing countries gain increased access to the finance, markets and networks necessary to start and grow a business,” a spokesman for Ms. Trump said.

The contribution comes as Mr. Trump’s administration weighs a drastic scaling-back of foreign aid as part of his “America First” campaign pledge to target federal funding to create jobs at home.

His budget, released in April but largely ignored on Capitol Hill, would include deep cuts to the United States Agency for International Development, a major conduit for foreign assistance.