Over the past year and a half, President Trump’s policy adviser and speechwriter Stephen Miller and Kirstjen Nielsen, the now ousted homeland security secretary, were locked in a bitter cold war of backbiting and paranoia.

By Sunday night, it was clear who had won.

Trump’s decision to dismiss Nielsen signaled not only that Miller had emerged victorious but also further solidified him as the premier anti-immigration hardliner and survivor in an administration notorious for prolific, rapid turnover at the highest levels.

Before everything came to a head early this week, the president had walked up to the line of sacking Nielsen several times, sometimes cooling off but inevitably getting re-energized by his own resentments, cable-news coverage of the border, and aides and advisers who re-enforced his instincts. Nielsen’s job was temporarily saved last year in part by her willingness to publicly and vociferously defend Trump’s controversial actions, such as deploying U.S. troops to the border late last year.

This was around the same time that Trump had told Fox News that he wanted Nielsen “to be much tougher on the border,” and suggested personnel changes were on the horizon.

But in recent weeks, the president asked Nielsen to bar all migrants, including those legally seeking asylum, from crossing into the United States via the southern border. When Nielsen reminded Trump that doing so would violate federal law, her reasoning only spiked the president’s rage further, according to The New York Times.

A senior White House official characterized this latest disagreement to The Daily Beast as a “last straw.”

By the weekend, the situation had reached a point where virtually all power centers in Trumpworld, in and out of the White House, had decided to elevate Nielsen as the scapegoat for internal frustrations regarding the influx of asylum seekers and continued attempts by migrants to cross into the U.S. without legal authorization.

Among many former Trump administration officials, her departure is a welcome shake-up. During most of her time in the administration, Nielsen and Miller were at odds. In fact, their working relationship became so tense that the two could barely be in the same room without making other top officials uncomfortable, two knowledgeable sources told The Daily Beast.

“Miller thought Nielsen was a soft-on-the-border Bushy, and she thought he was an egomaniacal lunatic who hated brown people. Needless to say, that made for awkward moments in the Oval [Office] and Cabinet Room,” said a former senior Trump administration official who has been in the room with both numerous times. The ex-official also described their professional relationship as one of clear “mutual disgust.”

“ Miller thought Nielsen was a soft-on-the-border Bushy and she thought he was an egomaniacal lunatic who hated brown people. ” — A former senior Trump administration official

A current administration official confirmed that Nielsen had a vanishingly low opinion of Miller and openly wondered if Trump’s senior policy adviser had often leaked against her to the press, or if he trash-talked her behind her back to the president.

Her instincts were right on the latter concern, as Miller made no secret of his feelings about Nielsen to Trump, according to multiple people familiar with the conversations.

Since the dawn of the Trump era, Miller has been a skilled but generally quiet knife fighter and operator behind the scenes, outlasting or outmaneuvering other senior officials, keeping on the president’s good side, and, as a result, expanding his reach of influence.

By mid-2017, Miller had elbowed his way deep into national security and foreign affairs deliberations, and used his clout to advocate dropping the cap on refugee admissions last year to a record low.

In an interview with The Washington Post, Sen. Charles E. Grassley (R-IA) said he was “very, very concerned” about the rapid-fire dismissals within the Department of Homeland Security and those who are rumored to be next on the chopping block. Grassley also took a jab at Miller, saying it would be “hard for him to demonstrate he’s accomplished anything for the president.”

“It’s pretty hard to elaborate on it when there hasn’t been any accomplishments,” Grassley added.

Those who know and have worked with Miller say he is shrewd in not infuriating Trump, knowing that too much of the limelight in Trumpworld can be fatal. He watched with a careful eye as Steve Bannon, Trump’s former chief strategist, rose within Trump’s ranks only to be sidelined after “President Bannon” storylines hyped his power and sway over the presidency.

Sensing Bannon’s demise was near, Miller turned on his former ally and trashed him to Trump, hastening Bannon’s exit from the West Wing.

With Nielsen, there’s even less love lost. But the internal antipathy aimed at Nielsen certainly didn’t end with Miller and the president. The sources noted how other senior aides, including Trump’s son-in-law, Jared Kushner, didn’t have Nielsen’s back, either.

She had also run afoul of one of Trump’s principal outside counselors, Fox Business host and immigration hardliner Lou Dobbs, who had repeatedly counseled Trump to ditch Nielsen in recent months, according to a person with knowledge of their private discussions.

Late last month, the Fox Business star dedicated part of his show to calling for the riddance of the “flailing” and “overwhelmed” DHS secretary.

It was the same mix of public and private pressure Dobbs used to urge Trump to can Jeff Sessions, the former attorney general who the president routinely denigrated as a failure, personally annoying, and mentally “retarded.”

A Fox Business spokesperson did not respond to a request for comment on this story. DHS and White House spokespeople didn’t immediately respond, either. But as The Daily Beast previously reported, Trump values Dobbs so much as a confidant and adviser that he has even had the TV host patched in on speakerphone during high-level Oval Office meetings.

Trump himself had on-and-off flirted with axing Nielsen, who he would often denounce as an ineffective softie on immigration and the southern border, despite Nielsen becoming a public face for Trump’s catastrophic family-separation policy, and her own fervent defenses of the administration’s more draconian measures. The president would make annoyed, screaming phone calls to Nielsen to thrash her for her perceived weakness, and he didn’t hesitate to berate her in front of colleagues during senior-level meetings, either.

“ She’s probably partially relieved and partially extremely frustrated. She was made a scapegoat, I think. She tried to do everything they wanted, but you cannot legally do everything they want. ” — A DHS official

“She’s probably partially relieved and partially extremely frustrated. She was made a scapegoat, I think. She tried to do everything they wanted, but you cannot legally do everything they want,” a DHS official told The Daily Beast. “To fix the issues that need to be fixed, you have to be able to come to a good-faith partnership with people across the aisle and put your heads together to actually work with Congress, and that’s completely impossible in this environment.”

Now that she’s out of a job, Nielsen reportedly has zero illusions about her diminished career prospects. During her time on Team Trump, she became a particular target, including for public confrontation, for liberal and left-wing activists who were determined to offer her no quarter for her prominent role in Trump’s family separations. In a letter this month signed by multiple advocacy organizations such as the Southern Poverty Law Center and Moms Rising, the groups implored Fortune 500 companies to blacklist Trump administration officials including Miller, Nielsen, and White House press secretary Sarah Huckabee Sanders.

“We call on you to make it clear that you will not hire for employment, contract for consulting, or seat on your boards, anyone involved in the development or implementation of the Trump administration’s family separation immigration policy,” the letter reads.

Speaking to reporters outside her home on Monday, Nielsen said she thanks Trump for the “tremendous opportunity to serve the country,” and that the two have a common goal in cracking down on the U.S.-Mexico border. Still, a s she plots her next move, Nielsen should expect little, if any, support from her former boss.

“Secretary of Homeland Security Kirstjen Nielsen will be leaving her position, and I would like to thank her for her service,” Trump had posted to Twitter on Sunday. A White House official told The Daily Beast that the president and White House’s lukewarm goodbye to her was fully “intentional.”

—With additional reporting by Max Tani and Betsy Woodruff