WASHINGTON — Kirstjen Nielsen, the homeland security secretary, resigned on Sunday after meeting with President Trump, ending a tumultuous tenure in charge of the border security agency that had made her the target of the president’s criticism.
“I have determined that it is the right time for me to step aside,” Ms. Nielsen said in a 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.”
Ms. Nielsen had requested the meeting to plan “a way forward” at the border, in part thinking she could have a reasoned conversation with Mr. Trump about the role, according to three people familiar with the meeting. She came prepared with a list of things that needed to change to improve the relationship with the president.
Mr. Trump in recent weeks had asked Ms. Nielsen to close the ports of entry along the border and to stop accepting asylum seekers, which Ms. Nielsen found ineffective and inappropriate. While the 30-minute meeting was cordial, Mr. Trump was determined to ask for her resignation. After the meeting, she submitted it.
The move comes just two days after Mr. Trump, who has repeatedly expressed anger at a rise in migrants at the southwestern border, withdrew his nominee to run Immigration and Customs Enforcement because he wanted the agency to go in a “tougher” direction.
Mr. Trump has ratcheted up his anti-immigration message in recent months as he seeks to galvanize supporters before the 2020 election, shutting down the government and then declaring a national emergency to secure funding to build a border wall, cutting aid to Central American countries and repeatedly denouncing what he believes is a crisis of migrants trying to enter the country.
He took aim again Sunday night after announcing Ms. Nielsen’s departure, tweeting, “Our Country is FULL!”
The president said in a tweet that Kevin McAleenan, the commissioner of Customs and Border Protection, would take over as the acting replacement for Ms. Nielsen, who became the sixth secretary to lead the agency in late 2017. But by law, the under secretary for management, Claire Grady, who is currently serving as acting deputy secretary, is next in line to be acting secretary. The White House will have to fire her to make Mr. McAleenan acting secretary, people familiar with the transition said. Ms. Grady has told colleagues that she has no intention of resigning to make way for Mr. McAleenan.
Among the possible replacements for Ms. Nielsen in the long term is Ken Cuccinelli, the former Virginia attorney general who is a favorite among conservative activists and who fits the profile that Mr. Trump wants the next homeland secretary to have, people familiar with the discussions said.
Ms. Nielsen had been pressured by Mr. Trump to be more aggressive in stemming the influx of migrant crossings at the border, people familiar with their discussions in recent months said.
Her entire time in the job was spent batting back suspicion from the president, even as he told people he liked how she performed on television and enjoyed dealing with her personally. He initially was skeptical because of Ms. Nielsen’s previous service in the George W. Bush administration, and then because she was close to John F. Kelly, Mr. Trump’s former chief of staff.
The president called Ms. Nielsen at home early in the mornings to demand that she take action to stop migrants from entering the country, including doing things that were clearly illegal, such as blocking all migrants from seeking asylum. She repeatedly noted the limitations imposed on her department by federal laws, court settlements and international obligations.
Those responses only infuriated Mr. Trump further. The president’s fury erupted in the spring of 2018 as Ms. Nielsen hesitated for weeks about whether to sign a memo ordering the routine separation of migrant children from their families so that the parents could be detained.
In a cabinet meeting surrounded by her peers, Mr. Trump castigated her repeatedly, leading her to draft a resignation letter and to tell colleagues that there was no reason for her to lead the department any longer. By the end of the week, she had reconsidered and remained in her position, becoming an increasingly fierce supporter of his policies, including the family separations.
Mr. Trump and Stephen Miller, the president’s top immigration adviser, have privately but regularly complained about Ms. Nielsen. Lou Dobbs, a Fox News host who is one of the president’s favorite sounding boards, has also encouraged Mr. Trump’s negative views of her handling of the migrant crisis.
Ms. Nielsen lost a powerful protector when Mr. Kelly, her mentor, left his job as White House chief of staff at the beginning of the year. Mr. Kelly was the Trump administration’s first homeland security secretary and lobbied for Ms. Nielsen to replace him.
Multiple White House officials said she had grown deeply paranoid in recent months, after numerous stories about her job being on the line. She also had supported the Immigration and Customs Enforcement nominee Mr. Trump withdrew, Ronald D. Vitiello, and her support for him was described as problematic for her with the president. Mr. Trump felt Mr. Vitiello did not favor closing the border, as the president threatened again to do in a tweet on Sunday night.
In early 2019, as the number of migrant families from Central American countries surged, the president’s fury at Ms. Nielsen did, too. He repeatedly demanded that she cut off foreign aid to Central American countries even though the funding was the responsibility of the State Department. She repeatedly deflected his demands.
One day after Ms. Nielsen traveled to Honduras to sign a regional compact with officials from Guatemala, Honduras and El Salvador, Mr. Trump cut State Department funding for the countries. And in recent days, the president made public moves to undercut her authority, leaking news that he might nominate an “immigration czar” to assume oversight of the issue at the heart of Ms. Nielsen’s department.
Still, Ms. Nielsen embraced the president’s “crisis” language as apprehensions of migrants at the border shot up to thousands per day. On Friday, Mr. Trump traveled with Ms. Nielsen and Mr. McAleenan to Calexico, Calif., to highlight the issue.
While the number of border crossings is not as high as in the early 2000s, the demographic of migrants has shifted largely from individual Mexicans looking for jobs — who could easily be deported — to Central American families, overwhelming detention facilities and prompting mass releases of migrants into cities along the border.
Ms. Nielsen estimated last month that border officials had stopped as many as 100,000 migrants in March.
But despite the trip and several stories about how much better her relationship with Mr. Trump was, Ms. Nielsen never learned how to manage him, people familiar with their discussions said. He often felt lectured to by Ms. Nielsen, the people familiar with the discussions said.
And his son-in-law, Jared Kushner, was not an admirer of Ms. Nielsen, several administration officials said. That came to a head recently as Mr. Kushner had inserted himself into immigration discussions.
While Mr. Trump often blamed Ms. Nielsen for the surge in migrant crossings, she will be remembered for leading the department during the Trump administration’s “zero tolerance” policy along the southwestern border, which initially resulted in the separation of thousands of migrant children from their families.
An intense backlash ensued, and the Department of Homeland Security was unprepared to deal with separating nearly 3,000 children from their parents.
“Hampered by misstep after misstep, Kirstjen Nielsen’s tenure at the Department of Homeland Security was a disaster from the start,” said Representative Bennie Thompson, a Mississippi Democrat and the chairman of the House’s committee on Homeland Security. “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.”
Mr. Trump eventually moved to halt the family separations, though the government struggled in some cases to reunite those it had already separated.
By naming Mr. McAleenan acting secretary, Mr. Trump is installing another veteran of previous administrations, not a loyal foot soldier of Mr. Trump’s campaign.
Married to a Salvadoran immigrant, Mr. McAleenan is a lawyer who wrote an honors thesis at Amherst College on marriage equality and applied at the F.B.I. after the Sept. 11 attacks.
Described by colleagues as a savvy political operator, Mr. McAleenan worked cooperatively with Obama administration officials but later embraced Mr. Trump’s agenda, which included unshackling Border Patrol agents from restrictions that the previous administration had imposed.
Mr. McAleenan was also one of three Department of Homeland Security officials who had urged Ms. Nielsen to sign the memo authorizing the routine separation of migrant families at the border.
The department, which has a budget of more than $40 billion and more than 240,000 employees, is an amalgam of 22 government agencies that was created after the Sept. 11 terrorist attacks. It is responsible for everything from protecting the nation from cyberattacks to responding to natural disasters.
At 46, Ms. Nielsen was the youngest person to lead the sprawling department, and an unlikely choice for the job.
In the months immediately after the Sept. 11 attacks, she helped set up the Transportation Security Administration, now an agency within the department. She also worked as a special assistant to President George W. Bush on natural disaster response while serving on the White House Homeland Security Council.
When Mr. Trump moved Mr. Kelly to the White House in July 2017, Ms. Nielsen moved with him. As the principal deputy chief of staff, she enforced Mr. Kelly’s attempts to regulate access to Mr. Trump in the Oval Office, including the president’s schedule — irritating White House staff members, who complained she was uncompromising.
Mr. Kelly later backed Ms. Nielsen to succeed him at the Homeland Security Department, though she was criticized as too inexperienced for the job by Democrats and anti-immigration groups. Mr. Trump, however, said she was “ready on Day 1.”
“There will be no on-the-job training for Kirstjen,” Mr. Trump said in October 2017, announcing her nomination for the post.
But by the following spring, Ms. Nielsen was telling associates she was miserable in the job.