Ms. Merkel has consciously avoided becoming Mr. Trump’s adversary. She dismissed efforts in Germany to portray her as a bulwark against his populist movement. Mr. Trump was harshly critical of Ms. Merkel during the campaign for allowing refugees into Germany, but he has moderated his words since taking office. He welcomed the chancellor to the White House for a full schedule of events that included an Oval Office meeting, lunch and a round-table discussion with German and American chief executives.

Still, both leaders advocated unapologetically for their worldviews. Mr. Trump appeared to go further than he has in the past on the need for burden-sharing in NATO. He demanded not just that members increase their military spending as a percentage of gross domestic product, but also that they make reparations for past American contributions.

“Many nations owe vast sums of money from past years, and it is very unfair to the United States,” he said. “These nations must pay what they owe.”

Mr. Trump also said he believed that Germany, like China and other trading partners, had taken advantage of the United States. “It’s not exactly good for our workers,” he said, adding that they had been “screwed.” The president said his “America First” approach had begun reversing that trend, luring factories back to Michigan, Ohio, Pennsylvania and other states that had lost manufacturing jobs to foreign countries.

Though Mr. Trump did not mention his executive order banning travel from six predominantly Muslim countries, he did say that “immigration is a privilege, not a right, and the safety of our citizens must always come first, without question.”

Ms. Merkel offered a vision of what she called “open-minded” globalization. Refugees, she said, needed opportunities to improve their lives, in part to stabilize their countries and prevent them from sliding into civil war. She extolled freedom of movement as one of the great strengths of the European Union. Germany’s success, she said, was inextricably tied to the success of the European Union.