Mr. McAleenan’s departure from the White House came after he tried to embrace the president’s increasingly aggressive assault on legal and illegal immigration publicly even as he privately resisted some of Mr. Trump’s most extreme ideas…

In an interview last week with The Washington Post, Mr. McAleenan complained about what he called the “tone, the message, the public face and approach” of immigration policy — a not-so-subtle reproach of the president’s own language.

The comments enraged some of the president’s staunchest allies, who had already targeted Mr. McAleenan for resisting nationwide deportation raids this year against migrant families.

Mr. McAleenan went to the White House on Friday to offer his resignation and volunteered to stay on the job until the end of the month, a move made in part to avoid having the president assert that he had forced him out, according to administration officials. In his resignation letter, Mr. McAleenan attributed his exit to “personal and family reasons” and described his tenure as “galvanizing and enervating.”