WASHINGTON — Secretary of Homeland Security Kirstjen Nielsen, who defended the separation of thousands of migrant children from their families on the southern border, carried out the most sweeping changes to U.S. asylum policy in decades, and saw two Guatemalan children die in her agency’s custody, resigned Sunday.

President Donald Trump announced the departure in a tweet, briefly thanking Nielsen for her service and saying that Kevin McAleenan, head of the U.S. Customs and Border Protection agency, will become acting secretary. The decision to name an immigration officer to the post reflects Trump’s priority for a department founded to combat terrorism following the Sept. 11 attacks.

In a resignation letter, Nielsen said she had “worked tirelessly to advance the goals and missions of the department,” but she had “determined that it is the right time for me to step aside.”

She did not detail any policy disagreements with Trump.

Her departure came two days after Trump blindsided Homeland Security officials by withdrawing the nomination of a career official, Ronald Vitiello, to head Immigration and Customs Enforcement, the Homeland Security agency that arrests and deports people who are in the country illegally.

Trump said at the time that he wanted to go “in a tougher direction.”

Nielsen’s departure will soon leave Trump’s 21-member Cabinet with only three women — Betsy DeVos at the Education Department, Elaine Chao at Transportation and Gina Haspel as head of the CIA. Linda McMahon, head of the Small Business Administration, announced that she will leave this month to take a position with a pro-Trump campaign committee.

Nielsen was responsible for implementing one of Trump’s most controversial initiatives, splitting up thousands of parents and children who crossed the southern border and holding them apart.

“I’m not a liar,” she said in a tense congressional hearing in December. “We’ve never had a policy for family separation.”

Federal courts later blocked the separations, and Trump formally ended the practice with an executive order.

Since then, Homeland Security and other U.S. officials have struggled to reunite separated children with their relatives by court-ordered deadlines, while some parents were deported without their children.

In January, inspectors for the agency that oversees the care of children in federal custody reported that the Trump administration probably separated thousands more children than previously thought, starting well before the “zero tolerance” policy was officially announced in spring of 2018.

Nielsen also took heavy criticism after a 7-year-old girl and then an 8-year-old boy, both from Guatemala, died while in Border Patrol custody within three weeks in December.

After the second child died on Christmas Eve, Nielsen decried the tragedy, saying that “the death of a child in government custody is deeply concerning and heartbreaking” and announcing efforts to provide better medical care along the border.

But she blamed the children’s parents, Congress, federal judges and others, rather than accept responsibility, though Customs and Border Protection operations and the Border Patrol are under Homeland Security.

Nielsen struggled to balance Trump’s sometimes unrealistic demands on immigration and her responsibilities as head of one of the largest departments in the federal government.

She always publicly defended Trump’s immigration crackdown, but Trump was known to belittle Nielsen and berate her in Cabinet meetings, blaming his Homeland Security secretary for what he viewed as a failure to stop border crossings and nearly leading her to resign or him to fire her several times.

Nielsen, 46, was an ally of Trump’s first Homeland Security secretary and later chief of staff, John Kelly, who also saw his relationship with Trump fray badly.

Nielsen joined the Trump administration in early 2017 as chief of staff to Kelly, and when the former Marine general moved to the White House, she followed as his deputy.

A month later, in October 2017, Trump nominated Nielsen to head Homeland Security.

The Senate confirmed her by a vote of 62-37 and Nielsen took office in December 2017.

Though Trump chose Nielsen for the job, he reportedly viewed her with suspicion because she had served as a special assistant to President George W. Bush, marking her as a member of the Republican establishment that Trump has criticized and battled.

Still, once in office, she publicly backed Trump’s long-promised border wall even as the administration struggled to secure the necessary funding from Congress, let alone follow through on Trump’s campaign pledge to make Mexico pay for it.

On Friday, she visited Calexico, Calif., for a ceremony where a plaque commemorating Trump was welded to a newly erected barrier that was originally planned in 2009.