Homeland Security Secretary Kirstjen Nielsen and Secret Service Director Randolph "Tex" Alles have been ousted, and at least two officials have been named as possibly heading out the door: US Citizenship and Immigration Services director Francis Cissna and Office of the General Counsel's John Mitnick.

"There is a near-systematic purge happening at the nation's second-largest national security agency," an official told CNN.

At least some of the sudden personnel changes come at the urging of White House senior adviser Stephen Miller, who played a key role in Nielsen's ouster. The President in recent weeks empowered Miller to lead the administration's border policies "and he's executing his plan" with what amounts to a wholesale decapitation of the department's leadership, an official said.

The President has also pushed in recent weeks to reinstate the family separation policy, which Nielsen resisted, a source familiar with the discussions says. Trump rescinded that policy amid public outrage and scrutiny from the courts last summer.

Miller's heightened influence within the West Wing has been aided by the President, who recently told aides in an Oval Office meeting that Miller was in charge of all immigration and border-related issues in the White House, according to a person familiar with the meeting.

Trump administration officials say Miller wants the President to dismiss Cissna and Mitnick.

Miller has always informally been one of the leading hardliner voices on immigration in the West Wing. But this change formalizes that role and gives him the ability to call and chair meetings on immigration issues. The change was first reported by The Washington Post

The sudden shift in personnel is indicative of the White House trying to redirect immigration policy following a surge of migrant apprehensions at the southern border in recent months.

Additionally, after Trump walked back his threat to close the US-Mexico border and praised Mexico for doing more to stop the flow of immigrants, he has since soured on his own walkback. By the end of the week, the President became frustrated once again about the issues at the border, dissatisfied that Mexico was not doing enough and looking for his aides to take tougher steps to address the problem.

The changes have left the department in limbo, which has had at least three positions filled by people in an acting capacity in senior roles.

A senior administration official said that under the law, DHS Under Secretary of Management Claire Grady, the current acting deputy secretary, is next in line of succession to be acting secretary. That means there are questions as to whether she will need to be fired as well in order to make Customs and Border Protection Commissioner Kevin McAleenan the acting DHS secretary, as Trump tweeted Sunday night.

Late last week, the White House abruptly withdrew the nomination of Ron Vitiello for director of Immigration and Customs Enforcement, which caught Congress and the department by surprise. Nielsen was unaware what was happening until after the nomination was pulled, a person familiar with the news said.

"It's pretty somber over here," said an ICE official, adding that there are still questions about why Vitiello's name was withdrawn.

'You've got a hard job'

Nielsen had been on thin ice for some time. After the 2018 midterm elections, she and her advisers strongly suspected that she would not survive long. The President had long talked about making changes to his Cabinet after the midterms, and Trump was increasingly calling for drastic action to curb migration at the southern border.

Nielsen realized that optics were what mattered most to Trump -- that's when she began to adopt a harder line and make a more public case for the President's immigration policies. In private, she also tried to adjust her style when talking to Trump, offering him workarounds to existing laws rather than simply telling him what he wanted at the border was not possible.

It all ingratiated her to Trump, according to multiple sources, and the President began to believe Nielsen might be the right person to implement his agenda despite the challenges of the job.

"You've got a hard job," the President told her at the time, a source familiar with the comments said.

At the same time, Nielsen worked with one of the President's closest advisers, his son-in-law, Jared Kushner, to broker a deal with Mexico that would allow some asylum seekers to wait in that country while their claims were processed. Nielsen also felt that forging a closer relationship with Kushner could help her get more stability in the job.

She entered 2019 feeling that she had earned that stability. In February, she reshuffled her senior staff and began to eye additional senior hires.

But the ground shifted under her faster than she could adjust. She began to grow concerned that her position might be in danger last week, when a newly empowered Miller indicated there would be a shake-up in several deputy-level positions at DHS.

Nielsen tried to find solutions to the administration's chaotic response to the situation at the border that would allow her to remain in her position. She started to talk to White House chief of staff Mick Mulvaney about bringing on an immigration czar to coordinate the administration's response -- and take some of the heat off herself.

Ultimately, neither that nor her attempts to turn up the volume on her rhetoric were enough.

"The situation at the border just deteriorated super quickly," one source close to Nielsen said.

Asked about the mood at DHS following Nielsen's resignation, one DHS official told CNN there was "some exasperation," adding that the department doesn't "have enough depth" to fill longtime vacancies.

"We are losing leadership faster than we can get it confirmed or even hired permanently," the official said.