BRUSSELS — President Trump assailed Germany on Wednesday and demanded that allies double their military spending targets, unleashing a broadside against NATO member countries just days ahead of his meeting with President Vladimir V. Putin of Russia.
But even as Mr. Trump raised questions about his commitment to NATO by lecturing European partners about leaning too heavily on the United States to protect them, he signed on to a summit declaration that emphasized strength and burden-sharing within the alliance and harshly criticized Russia for its annexation of Crimea.
The contrast reflected a growing disconnect between Mr. Trump and the more traditionally minded foreign-policy advisers in his government when it comes to the role of the United States on the world stage. While his aides and advisers toil privately to maintain American global leadership, post-World War II institutions and strong alliances, the president appears bent on challenging if not upending those conventions to get what he considers a better deal for the United States — even if he does not follow through on all of his threats.
Mr. Trump was primed for confrontation before the gathering was ever called to order here in a large glass-and-steel NATO headquarters building that he has complained looks overly lavish. At a breakfast with Jens Stoltenberg, the NATO secretary general, Mr. Trump made it clear that he had come to Brussels as a virtual pariah among allies, and was perfectly happy to be seen that way.
“I think the secretary general likes Trump,” he said, alluding to allies’ stepping up their military spending in response to his pressure tactics. “He may be the only one, but that’s O.K. with me.”
Indeed, Mr. Trump spent the next several few hours practically ensuring it. He laid into Germany for not spending more on its military while becoming increasingly dependent on Russia for its energy needs, calling it a “captive of Russia.” His criticism was based on Germany’s deal to import natural gas from Russia.
He dismissed as paltry — “a very small step,” the president said — the increases that NATO member countries have made in their military budgets in part because of his repeated lectures on the issue.
“Frankly, many countries owe us a tremendous amount of money for many years back, where they’re delinquent, as far as I’m concerned, because the United States has had to pay for them,” Mr. Trump said, mischaracterizing how the commitments for NATO military spending work. “This has gone on for many presidents, but no other president brought it up like I bring it up.”
“Something has to be done,” Mr. Trump added.
Behind closed doors, Mr. Trump suggested that NATO allies increase their military budgets not to the 2 percent of their economies that they have pledged to work toward within the next six years, but to 4 percent — a steep increase that is inconceivable for many member countries. Later, he took to Twitter to demand that member countries get to 2 percent “IMMEDIATELY, not by 2025.”
Yet unlike at the Group of 7 meeting in Quebec last month, Mr. Trump did not refuse to sign the NATO declaration, although it was a mark of how much uncertainty he has created among allies that news of his agreement to the basic statement of principles and goals was not a foregone conclusion.
The first day of the summit meeting offered a stark portrait of an American president who is more comfortable using sharp elbows, and less willing than ever to be restrained by aides and advisers.
It also reflected the degree to which Mr. Trump, ever preoccupied with his popularity and looking toward midterm congressional elections in which the Republicans’ control of Congress is at stake, believes that attacking Europe and NATO play well with his political base. The populist core of his support is fueled in part by anger over what they consider unfair treatment of the United States on matters of trade, immigration and international affairs.
“I think he feels it’s playing well with his base, fueling this sense of grievance against allies and trading partners, which is how he got elected,” Alexander Vershbow, a former NATO deputy secretary general, said of Mr. Trump in an interview.
“The danger,” Mr. Vershbow said, “is that he’s turning at least his base, and maybe other Americans, against NATO and against U.S. global leadership by falsely defining it as a protection racket where we haven’t been paid enough by the protectees, rather than as a mutually beneficial alliance that has kept peace and expanded the frontiers of democracy.”
Mr. Trump’s condemnation of Germany also highlighted his determination to turn the tables on his critics, at a distance if not in person.
By pointing out the close connections between Germany and Russia on the Nordstream II gas pipeline, and the degree to which they depend on each other financially, Mr. Trump was borrowing a page from his critics who suggest that because of Russia’s interference in the 2016 election on his behalf, he is beholden to Mr. Putin. It was a way of implying that it is Germany’s leader, not he, who is too compromised to be able to effectively counter the Russian president.
“The former chancellor of Germany is the head of the pipeline company that’s supplying the gas,” Mr. Trump said, referring to Gerhard Schröder, a former German chancellor and friend of Mr. Putin’s who leads the project. “So you tell me, is that appropriate?”
One senior White House official, who spoke on the condition of anonymity so as not to describe interactions with the president, said that Mr. Trump was aware of — and had groused about — the criticism that he is too close to Mr. Putin. That official considers Mr. Trump’s comment about the pipeline — which echoed security concerns voiced by the Obama administration — an effort to hit back at what the president feels is a double standard about his relationship with Russia.
Jorge Benitez, a senior fellow at the Atlantic Council, said Mr. Trump’s comment was further evidence that he is acting alone and on instinct, and was willing to sow unrest in Brussels that would ultimately be a boon to Mr. Putin.
“It is in Russia’s interest, not the U.S. interest, for the Europeans to have any doubt about U.S. commitment to its allies,” Mr. Benitez said of the president’s actions. “In trying to get a better deal, he will severely harm the unity of the alliance.”
Katie Rogers contributed reporting.