Homeland Security Secretary Kirstjen Nielsen resigned on Sunday after mounting frustration by President Donald Trump over his administration's failure to stop the flow of migrants into the country.

Trump announced the resignation on Twitter, and Nielsen issued a resignation letter a few minutes later.

Kevin McAleenan, the commissioner of Customs and Border Protection, will become acting secretary pending confirmation of Nielsen's successor, Trump said. Nielsen said Sunday night on Twitter that she would stay until Wednesday to help with the transition.

Secretary of Homeland Security Kirstjen Nielsen will be leaving her position, and I would like to thank her for her service.... — Donald J. Trump (@realDonaldTrump) April 7, 2019

As recently as last week, Nielsen was busily announcing plans to reassign hundreds of Customs and Border Protection agents to the southern border to "address the influx of migrants" in certain areas.

But Nielsen, 46, has suffered from tepid support within the administration, taking public responsibility for Trump's deeply divisive anti-immigration policies.

Nielsen said in her resignation letter that she was proud of her tenure at Homeland Secretary, asserting that "our homeland is safer today than when I joined the administration."

But "I hope that the next secretary will have the support of Congress and the courts in fixing the laws that have impeded our ability to fully secure America's borders and which have contributed to discord in our nation's discourse," she said.

Her departure comes just two days after she and Trump visited the U.S. border with Mexico and three days after the president withdrew his nomination of Ronald Vitiello to be the director of Immigration and Customs Enforcement.

The president was frustrated with Nielsen's tenure as secretary and accepted her resignation after a meeting at the White House on Sunday night, according to two people familiar with the matter, one of them a senior U.S. official and the other a person who is close to Nielsen.

The frustration, which had been mounting for weeks, was mutual, according to the person close to Nielsen. Their poor relationship was exacerbated by Trump's failure to consult with her on his decision to withdraw Vitiello's nomination, according to the person.

The president gave Nielsen the opportunity to resign, but he clearly wanted her to leave, according to a third person familiar with the matter.

Before the announcement, Fox News' anchors had persistently called for her resignation, claiming that she was ineffective and needed to leave.

She has also faced fierce criticism from within and outside the department, which is the subject of numerous House subpoenas and more than 20 investigations by the agency's own inspector general.

"Hampered by misstep after misstep, Kirstjen Nielsen's tenure at the Department of Homeland Security was a disaster from the start," Rep. Bennie G. Thompson, D-Miss., chairman of the Homeland Security Committee, said in a statement.

"It is clearer now than ever that the Trump administration's border security and immigration policies — that she enacted and helped craft — have been an abysmal failure and have helped create the humanitarian crisis at the border," he said.

But Rep. Mike Rogers of Alabama, the committee's ranking Republican, said Nielsen "served her country honorably as homeland security secretary despite facing numerous challenges including dire conditions at our southwest border."

Nielsen has run Homeland Security, the federal government's third-largest department, without a deputy ever since she succeeded John Kelly as secretary in December 2017 after Kelly became White House chief of staff.

Trump has expressed his frustration with the situation on the border for months, at times threatening to shut down all points of entry with Mexico and demanding that both the Mexican government and Congress do more to solve with the president persistently calls a "crisis."

"The system is full. We can't take you anymore," Trump said at a roundtable event with law enforcement officials and local leaders at a border patrol station in Calexico on Friday. "Our country is full. ... Turn around."

"When it's full, there's nothing you can do. You have to say, 'I'm sorry, we can't take you,'" he said.

McAleenan, who was confirmed as head of CBP in March 2018, was deputy commissioner of the bureau, the nation's largest law enforcement agency, during President Barack Obama's administration.

Kevin McAleenan, commissioner of U.S. Customs and Border Protection, will become acting secretary of homeland security after President Donald Trump announced that Secretary Kirstjen Nielsen was leaving the position. Andrew Harnik / AP file

His confirmation to head CBP was delayed for more than three months as allegations emerged that anonymous accusers had alleged that McAleenan had an affair with a subordinate and bypassed proper channels to fund an immigration detention center. DHS' inspector general cleared him of wrongdoing at the time.

CBP came under investigation by the House Homeland Security Committee last month after NBC News and NBC San Diego reported that it had compiled a list of 59 reporters, lawyers and activists, most of them U.S. citizens, who were to be stopped for questioning crossing the U.S.-Mexican border at San Diego-area checkpoints. At least 21 of them have been stopped and questioned or arrested.

"CBP does not target journalists for inspection based on their occupation or their reporting," the agency responded. "CBP has policies in place that prohibit discrimination against arriving travelers and has specific provisions regarding encounters with journalists."

"Commissioner McAleenan will have his work cut out for him," Rogers said. But "I am confident the department is in capable hands."