“To those few Senators who think I don’t like or appreciate being allied with other countries, they are wrong, I DO,” Mr. Trump wrote in a pair of tweets critical of Jim Mattis, his departing defense secretary. “What I don’t like, however, is when many of these same countries take advantage of their friendship with the United States, both in Military Protection and Trade.”

Mr. Trump added: “General Mattis did not see this as a problem. I DO, and it is being fixed!”

Mr. Mattis’s resignation letter on Thursday served as a rebuke of the president’s sharp demands of America’s allies and softened approach toward some of its adversaries. Only over the weekend did Mr. Trump realize that Mr. Mattis’s letter was a critique of the president’s policies, leading him to accelerate Mr. Mattis’s departure.

The resignation was prompted by Mr. Trump’s abrupt decisions last week to pull troops from Syria and Afghanistan. Those moves have plunged some of the United States’ longest allied partners into uncertainty as they grapple with an American leader who largely treats those relationships as bottom-line business transactions.

Global leaders have also echoed Mr. Mattis’s rebuke of Mr. Trump’s worldview.

“I very deeply regret the decision made on Syria,” President Emmanuel Macron of France said during a news conference over the weekend. “To be allies is to fight shoulder to shoulder. It’s the most important thing for a head of state and head of the military. An ally should be dependable.”