Julianne Smith, director of the Trans-Atlantic Security Program at the Center for a New American Security, said that “European officials are thinking about how to respond, about what it costs them politically at home and what it costs them bilaterally, with Washington.”

The Europeans are also anxious about the fate of Mr. Mattis, who is an outspoken supporter of the NATO alliance and an aggressive stance toward Russia.

With John Bolton as national security adviser and Mike Pompeo as secretary of state, Mr. Trump has rejected the defense secretary’s advice on North Korea and on preserving the Iran nuclear deal.

At the Group of 7 meeting, Mr. Trump approached some European leaders and asked them for their thoughts on Mr. Mattis, said Ms. Smith, who was deputy national security adviser to Vice President Biden.

“It was awkward for them and might be the kiss of death,” if they praised him, she said, “so they said deliberately that he is being so tough on us on 2 percent defense spending, to try to save the guy.”

Everyone understands that Mr. Trump will want a discussion about “burden-sharing” and the commitment of all NATO allies, made at their Wales summit meeting in 2014, to aspire to spend 2 percent of their gross domestic product on defense and 20 percent of military spending on equipment by 2024.

But they worry about how heated, and how public, it might get. Mr. Trump’s past comments suggest that he thinks that there is some NATO treasury to which members owe dues, and that allies are behind on their payments.