But Europe is changing, too, with Britain seeking to leave, Ms. Merkel nearing the end of her tenure, and Mr. Macron staking his claim to European leadership with a vision of the future that depends less on the United States. His criticism of NATO is inevitably, if indirectly, a criticism of Mr. Trump and his “America First” policy.

As Europe changes, Mr. Trump is finding that he has to recalibrate his approach. With his own re-election campaign looming, he also wants credit for what he views as his foreign policy accomplishments, including NATO. On the first day of his London trip, it made for some remarkable political theater.

The president who once threatened to pull the United States out of NATO suddenly emerged as the alliance’s defender. The president who once exchanged a death-grip handshake with Mr. Macron sat by wordlessly while his much-younger counterpart lectured him on the need to fight the Islamic State. The president who championed Brexit and hectored Mr. Johnson’s predecessor, Theresa May, about her deal-making skills suddenly had nothing to say about it.

Asked about the British election, Mr. Trump resorted to talking about how his campaigning had helped Republican gubernatorial candidates in Kentucky and Louisiana — never mind that both men lost — before implicitly acknowledging that his involvement in Britain would probably not help.

“I love this country,” Mr. Trump said. “I love a lot of countries, but I’m representing the U.S. They may not like me because I’m representing us, and I represent us strong.”

The president has always viewed statecraft as both highly personal and strictly transactional, which makes some experts wary of drawing overly broad conclusions from Mr. Trump’s early performance in London. His clash with Mr. Macron, they said, may reflect as much personal pique about Mr. Macron’s assertive style as basic disagreements over the future of NATO.

“At the moment, Macron has replaced Merkel as his nemesis,” said Thomas Wright, the director of the Center on the United States and Europe at the Brookings Institution, “but I could see them working together in a few months.”