In his letters, the president hinted that after more than a year of public and private complaints that allies have not done enough to share the burden of collective defense, he may be considering a response, including adjusting the United States’ military presence around the world.

“As we discussed during your visit in April, there is growing frustration in the United States that some allies have not stepped up as promised,” Mr. Trump wrote to Chancellor Angela Merkel of Germany in a particularly pointed letter, according to someone who saw it and shared excerpts with The New York Times. “The United States continues to devote more resources to the defense of Europe when the Continent’s economy, including Germany’s, are doing well and security challenges abound. This is no longer sustainable for us.”

“Growing frustration,” Mr. Trump wrote, “is not confined to our executive branch. The United States Congress is concerned, as well.”