BERLIN – President Barack Obama wrapped up his final visit to Europe on Thursday by issuing a plaintive warning to Western democracies not to “take for granted our system of government and our way of life” as he prepares to relinquish the international stage to his successor, President-elect Donald J. Trump.

“Democracy is hard work,” Obama said at a news conference after meeting here with German Chancellor Angela Merkel, one of his closest international partners. Ahead of their meeting, the pair had delivered a joint rebuttal to Trump’s populist pledges, calling in a joint newspaper op-ed for more transatlantic cooperation on everything from security and climate change to fighting intolerance.

Speaking to reporters, Obama tried to remain optimistic about the prospect of a Trump presidency, despite having sharply criticized him as tempermentally unfit for office during the long, bitter campaign. The president had mocked Trump as unworthy of being trusted with the nuclear codes as someone who could be “baited with a tweet.”

Obama, without directly naming Trump, appeared critical of the political discourse in the United States, saying social media has made it easier “to make negative attacks and simplistic slogans than it is to communicate complex policies.”

“If we are not serious about the facts and what’s true and what’s not, particularly in the social media era when so many get information from sound bites and snippets off their phone, if we can’t discriminate between serious arguments and propoganda, then we have problems,” Obama said. He warned that if the two political parties remain wedded to “absolutist views” and refuse to compromise “then democracy will break down.”

On his last overseas trip as president, Obama met with Merkel, a centrist leader whom observers see as the heir apparent to his legacy as the leading global advocate of liberal democracy.

Ahead of a joint appearance later Thursday, the two penned an op-ed piece recognizing the painful side of freer trade along with a sober reality check.

“The future is upon us, and we will never return to a pre-globalization economy,” they wrote.

The two leaders never mentioned Trump by name. But their statements appeared to serve as a point-by-point rejection of some of the president-elect’s most contentious foreign policy pledges.

They defended aid for refugees “because we know it is our treatment of those most vulnerable that determines the true strength of our values.” They hailed the North Atlantic Treaty Organization – from which Trump has threatened to pull back – as a cornerstone of peace. They presented the German-U.S. relationship as a symbol of shared progressive Western values.

“Our countries share a joint responsibility to protect and preserve our way of life,” the two leaders wrote in the German weekly Wirtschaftwoche. “It is in this spirit that we are working hard to ensure that international law and norms are respected around the globe – which remains a prerequisite for stability and prosperity.”

They strongly argued in favor of pursuing a free trade deal between the United States and the European Union despite Trump’s vows to upend it after years of talks. They also heralded the Paris Agreement to cut global emissions – from which Trump has threatened to withdraw – as a deal that “gives the world a framework for the common protection of our planet.”

Despite earlier reservations, several global leaders appear to be rushing to congratulate Trump – signaling either a pragmatic willingness to cooperate with the president-elect or a desire to size him up. Japanese Prime Minister Shinzo Abe, for instance, is rushing to New York for an early meeting with Trump.

But Merkel, considered the E.U.’s most influential leader, is taking a significantly cooler approach, continuing to align herself with Obama even as he exits the global stage. She has treated Trump with caution so far. Following his surprise victory, Merkel issued a carefully worded message of congratulations signaling her desire to cooperate, but only on the basis of “democracy, freedom, as well as respect for the rule of law and the dignity of each and every person, regardless of their origin, skin color, creed, gender, sexual orientation, or political views.”

That is in part because, for Obama, Merkel is something a political soul mate. No other world leader so closely matches Obama’s ideology of tireless diplomacy with an emphasis on human rights, tolerance and equality.

Sharing similar temperaments, Merkel and Obama forged a friendship that helped broker several major agreements – including the deal on Iran’s nuclear program and sanctions against Russia for its annexation of Crimea and intervention in eastern Ukraine.

Although she hails from what in liberal Germany is considered to be the center-right, Merkel is seen as emerging, after Obama, as a leading global voice for progressive values, including equality, renewable energies and tempered diplomacy in the face of conflict.

Importantly, Merkel has not yet said if she will seek reelection in national elections next year – but the RND newspaper network reported Thursday, citing unnamed party sources, that she would announce her decision on Sunday. Some of her close allies have suggested she will run.

Obama’s last overseas trip started in Greece, where he delivered a major speech on Wednesday warning against “crude nationalism.” He arrived later in Berlin for an informal dinner with Merkel, with formal talks and a news conference with the chancellor on Thursday. On Friday, he meets again with Merkel along with the leaders of France, Britain, Italy and Spain before flying to Peru.

It is perhaps fitting that Obama bids farewell to Europe in Germany, the nation where his massive outdoor rally as a candidate more than eight years ago turned him into a global phenomenon. Although he has had ups and downs with the public here, Germans appeared to turn nostalgic during his last trip.

“Looking back, it now slowly sinks in, that we fared very well with Obama,” the Leipziger Volkszeitung newspaper said in an editorial Thursday.

“Yes, he got the Nobel Peace Prize far too early. He didn’t shut Guantánamo. He couldn’t pacify Syria. But still this president had an important impact on the relationship with Europe. . . . He actually practiced the ‘common leadership’ that his predecessors only spoke about in abstract terms.”