WASHINGTON – Kirstjen Nielsen, who oversaw President Donald Trump's hard-line immigration policies as secretary of Homeland Security, is leaving her post amid tensions with some in the White House who felt she hasn't done enough to stem border crossings.

Trump tweeted Sunday that Nielsen is leaving the post she has held since the end of 2017.

"Secretary of Homeland Security Kirstjen Nielsen will be leaving her position, and I would like to thank her for her service," he said. He said Kevin McAleenan, the U.S. Customs and Border Protection commissioner, will become the acting DHS secretary. McAleenan has held senior posts within CBP dating back to President George W. Bush's administration.

"Despite our progress in reforming homeland security for a new age, I have determined that it is the right time for me to step aside," Nielsen said in her resignation letter. "I hope that the next Secretary will have the support of Congress and the courts in fixing the laws which have impeded our ability to fully secure America's borders and which have contributed to discord in our nation's discourse."

She later tweeted that she would remain in her post until Wednesday to "assist with an orderly transition and ensure that Key DHS missions are not impacted."

White House departures:Who's been fired and who resigned

Nielsen's departure comes as a surge of migrants has overwhelmed the U.S. immigration system in recent months. In response, Trump threatened to close the border and cut off aid to the Central American countries that migrants continue to flee. Trump visited the border in Calexico, California, on Friday along with Nielsen.

'Breaking point'? Cutting aid and closing ports: Here's what's happening at the southern border

Nielsen has voiced increasing frustration at the situation, which the administration considers a national security crisis, and last week she compared it to a Category 5 hurricane.

"The rate at which this crisis is evolving is tremendous," she said Thursday in an interview on CNN. "So we absolutely need additional resources, more than we can reprogram or otherwise use under executive authority without Congress."

"We have tried everything that we can at DHS."

In her resignation letter, which she shared on Twitter, Nielsen said it had been an honor to lead the agency but that “I have determined that it is the right time for me to step aside.”

“I hope that the next secretary will have the support of Congress and the courts in fixing the laws which have impeded our ability to fully secure America’s borders and which have contributed to discord in our nation’s discourse,” she said. “Our country – and the men and women of DHS – deserve to have all the tools and resources they need to execute the mission entrusted to them.”

“I can say with confidence the homeland is safer today than when I joined the administration,” she concluded.

Nielsen's departure comes amid an exodus of Cabinet and other senior officials in the Trump administration following the November midterm election. Nielsen's longtime ally, White House chief of staff John Kelly, stepped down in December. Defense Secretary Jim Mattis also resigned in December amid a broader shakeup among Trump's military advisers.

Nielsen had a turbulent tenure in which Trump upbraided her to pursue his policiesmore aggressively. In 2018, she became a lightning rod while defending the administration's zero-tolerance policy that led to separating more than 2,500 children from parents who crossed the border illegally from April 2018, when then-Attorney General Jeff Sessions announced the program, until Trump rescinded the effort in June.

But as an unprecedented number of immigrants were requesting asylum, Trump blasted Nielsen during a May Cabinet meeting for ineffective border enforcement. Halting illegal immigration energizes his supporters and he hammered the issue before the midterm election.

More recently, caravans of thousands of immigrants have headed across Mexico. In October, the Defense Department deployed 5,200 troops to support 16,500 CBP officers along the southern border to deal with the influx. Critics called an election-year ploy to incite hatred and fear.

In late November, migrants clashed with border patrol agents at the San Ysidro port near San Diego. Some migrants threw rocks and bottles at officers, who responded with tear gas. The U.S. government shut down the country's busiest port briefly to better barricade the vehicle lanes.

“As I have continually stated, DHS will not tolerate this type of lawlessness and will not hesitate to shut down ports of entry for security and public safety reasons," Nielsen said Nov. 25.

The death of a 7-year-old Guatemalan girl, Jakelin Caal Maquin, who died in CBP custody Dec. 8, reignited the emotional debate over immigration in Congress. CBP had apprehended her two days earlier among a group of 163 migrants. Nielsen said the case exemplified the human misery of illegal immigration and illustrated why strict border security was needed, to discourage the dangerous journey.

"We face a crisis at our border, a real serious and sustained crisis," Nielsen told the House Judiciary Committee on Dec. 20. "We have tens of thousands of illegal aliens arriving at our doorstep every month. We have drugs, criminals, and violence spilling into our country every week and we have smugglers and traffickers who profit from human misery every single day by exploiting people who are seeking a better life, deceiving them about our laws, and fueling everything from sexual slavery to the smuggling of illicit goods.

At that hearing, Nielsen unveiled a policy to forbid anyone seeking asylum at the southern border from waiting in the United States. Instead, the migrants would be forced to stay instead in Mexico while awaiting adjudication.

"They will not be able to disappear into the United States," Nielsen said. "They will have to wait for approval to come into the United States."

More:Report: Homeland Security Secretary Kirstjen Nielsen almost resigned over Trump tirade

More:Senators grill DHS Secretary Kirstjen Nielsen over child detentions under ‘zero-tolerance’ policy at border

More:Nielsen: Trump considering 'every option' to stop migrant caravan from reaching the border

Trump’s push for $5.7 billion to build a wall along the southern border led to a bitter fight with congressional Democrats late last year and resulted in a record 35-day government shutdown.

In the aftermath of the shutdown, Trump declared a national emergency and authorized his administration to dip into budgets for other agencies, including the Department of Defense, to fund the project.

The Democratic-led House filed suit against Trump on Friday to try to prevent him from going around Congress to fund his wall. The suit argues Trump overstepped his constitutional powers when he authorized spending more money than Congress has approved to erect the barrier. Other similar lawsuits also have been filed to halt Trump’s emergency declaration.

Nielsen was sworn in Dec. 6, 2017, to lead the sprawling department with 240,000 workers. Besides CBP and Immigration and Customs Enforcement, the department overseesthe Transportation Security Administration, the Secret Service, the Coast Guard and the Federal Emergency Management Agency. Her first volatile year required dealing with hurricanes and a mail-bomb case that targeted high-profile individuals.

Nielsen, who had helped set up TSA under President George W. Bush, wasn't seen as a Trump loyalist. She succeeded Kelly as secretary when he became White House chief of staff. While Kelly initially protected her, he fell out of favor with Trump and provided less of a shield.

Border security had been contentious between Trump and Nielsen for months. Nielsen tried to explain the issues were complex and that the department's powers were limited by a slew of legal restrictions.

A week after the critical Cabinet meeting in May, Nielsen defended the zero-tolerance policy and said family separations happened as a result of enforcing immigration laws riddled with "loopholes."

"Congress needs to fix it," Nielsen told reporters during a briefing specially arranged at the White House. "It's a problem; let's fix it."