There is no such rapport between the flamboyant Mr. Trump and the brainy, button-down Ms. Merkel.

The two have a businesslike relationship, officials on both sides said. But Ms. Merkel, several officials said, has concluded that there is little prospect of closing the gap with Mr. Trump on issues like trade, Russia or the Paris climate accord, which Mr. Trump has threatened to leave. Her defiant tone on Sunday was driven in part by the fact that she is running for re-election and that Mr. Trump is deeply unpopular in Germany.

Whatever the motivation, it seemed to register with Mr. Trump. “I think it just stuck in his craw,” said Jackson Janes, president of the American Institute for Contemporary German Studies at Johns Hopkins University.

White House officials said it was the combination of Germany’s wealth and its meager contribution to NATO that singled it out for criticism. Germany spends only 1.2 percent of its gross domestic product on defense, compared with 1.8 percent for France. Both are below the 2 percent threshold that NATO has set for its members.

Germany’s trade surplus is a ripe target for Mr. Trump. It is mammoth — $64.8 billion in 2016 — and longstanding, and there is little evidence that Germany, which regards its export machine as a source of national pride, is inclined to do much to remedy it.

German officials typically tell their American counterparts that the surplus reflects the competitiveness of German goods, that Germany does not set its trade policy, and that it cannot control the value of the euro, since monetary policy is set by the European Central Bank, not Berlin.

Mr. Trump is not the first American leader to be rankled by imbalances with Germany. President Barack Obama’s economic advisers, Jacob J. Lew and Lawrence H. Summers, pushed German officials on these issues, with little success. But Mr. Trump is more acutely aware of the deficit because jobs and trade are such resonant issues with his voters.

John C. Kornblum, a former American ambassador to Germany, said the president’s views “seem to be a mixture of his own resentments from not being able to push his business deals through the E.U. as he wished; broad prejudices which have been building up in the American political class for some time on both NATO and trade; and the conviction of his economic advisers that the German trade balance is an evil, which causes many other problems from job losses to currency instability to loss of American exports.”