WASHINGTON — Just last month, Kirstjen Nielsen, the homeland security secretary, drafted a resignation letter after being berated by President Trump over what he saw as her tepid support for his tough immigration policies, according to two people familiar with the episode. She never sent it.

This week, confronted by images of children in cages after they had been separated from their families at the Southwest border, Ms. Nielsen served as a shield for the Trump administration against global criticism for its hard-line attempts to discourage illegal immigration.

Smiling as she took the White House lectern on Monday, Ms. Nielsen read from a script defending Mr. Trump’s “zero tolerance” policy, which has separated 2,300 children from their parents yet failed to reduce the number of families trying to cross the border. She falsely said that Mr. Trump’s family separation strategy was not administration policy, wrongly insisting it was the result of legal “loopholes” that only Congress can fix.

Asked whether images of young children packed into detention centers and an audiotape of them keening for their parents were intended or unintended consequences of the administration’s decision making, Ms. Nielsen replied: “They reflect the focus of those who post such pictures and narratives. The narratives we don’t see are the narratives of the crime.”