WASHINGTON — Amid the chaos, Stephen Miller is in charge now.

The iconoclastic hard-line young conservative policy aide to President Donald Trump, hated by the left, and celebrated by the extreme right, is the obvious winner in the power struggle that led to Kirstjen Nielsen's ouster Sunday night as Homeland Security secretary.

Miller has unofficially taken the reins of border security amid a purge at the department that has also seen Secret Service Director Randolph "Tex" Alles removed from his job and Trump's pick to head the Immigration and Customs Enforcement agency, Ron Vitiello, yanked.

The Department of Homeland Security, a sprawling agency charged with defending the nation at home, does not have Senate-confirmed officials in the roles of secretary, deputy secretary, ICE chief, Secret Service director or inspector general. When Kevin McAleenan, who has been tapped to take over Nielsen's job on a temporary basis, moves into his new digs, there won't be a Senate-confirmed leader at Customs and Border Protection, either.

Miller has always had a strong hand in the administration's internal wars over immigration policy, but now there's no one left to fight him.

"Stephen Miller's fingerprints are all over Secretary Nielsen's resignation letter," said Dan Eberhart, a major Republican donor who is in touch with administration officials. "Trump wants to double down on the immigration strategy and Nielsen was apoplectic at the idea of closing the border."

That letter reads as an explanation of Trump's lurch to a more aggressive crackdown on immigration in the aftermath of his failure to use a government shutdown to force Congress to fund his promised border wall, amid a burgeoning humanitarian crisis brought on by his administration's inability to handle an influx of Central American migrants and in preparation for his re-election bid.

"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," Nielsen wrote in the letter released after a White House meeting late Sunday in which she either resigned or was fired.

"I can say with confidence our homeland is safer today than when I joined the Administration. ... We have implemented historic efforts to defend our borders, combat illegal immigration, obstruct the inflow of drugs, and uphold our laws and values," she wrote.

Her message, in short: that Trump has done everything he can to stop undocumented immigrants from coming into the United States and Congress is to blame for any shortcomings on that front.

At a time when Trump is teeing up a "promises made, promises kept" re-election slogan, that's the way he's choosing to frame the fact that his border policy hasn't yet produced the wall he promised to build along the border, hasn't stemmed the tide of immigrants seeking to cross into the U.S., and hasn't addressed the humanitarian crisis — overflowing detention centers, medical needs and an inability to process asylum-seekers — that didn't exist when he first proposed the wall.

Trump had a crisis in confidence with regard to Nielsen, but the humanitarian emergency at the border threatens to create a crisis in competence for his administration.

If illegal immigration was a problem before Trump took office, it has become worse — not better — since then, and he is looking for scapegoats. Nielsen, disliked by the right for opposing some of Trump's harshest tactics, and by the left for becoming the public face of unpopular policies like separating children from their parents as a means of deterring future immigrants, was a convenient fall woman.

Her departure comes as Trump is turning hard toward the Miller playbook, which is full of take-no-prisoners policies and rhetoric that demonizes immigrants. If Trump is unable to bend Congress, his own administration, other countries and immigrants to his will, he'll be sure to tell his immigration-obsessed base that he only failed because he didn't have enough power. And he'll ask for more in the form of another term, more Republican members of Congress and the ability to appoint a new slew of conservative judges to federal courts.

That's the Miller way, and Trump has little choice politically but to follow it after alienating liberals and moderates with his immigration policy so far.

His re-election strategy depends on locating Americans who agree with him but don't usually vote and driving them to the polls in droves. That, he has clearly concluded, means taking the hardest possible line on immigration and presenting it primarily as a security issue, even if there is a legitimate humanitarian crisis playing out at the border now.

It was Miller, the Duke University-educated senior policy adviser, now 33, who helped scuttle Trump's plans to cut a deal with Democrats in the summer of 2017 that would have traded deportation protections for immigrants who were brought to the U.S. illegally as children under the Deferred Action for Childhood Arrivals program for as much as $25 billion in funding for the border wall.

The White House quickly moved past that deal and made a counteroffer with a buffet of Miller policy favorites that were poison pills for congressional Democrats, including caps on legal immigration and an end to preferences for family members of immigrants who came to the U.S. legally.

In recent days, Trump has threatened to seal the border, drawing condemnation from economists and some prominent figures in his own party because of the potential cost to the economy; announced he will end foreign aid to Nicaragua, El Salvador and Guatemala even though that might lead to more migration from those countries to the U.S.; and publicly told asylum-seekers to "go home."

This past weekend, he told a Republican Jewish Coalition audience in Las Vegas that he was not interested in providing asylum to refugees.

"Our country is full, can’t come," he said. "I’m sorry."

Nielsen, who was a favorite of former Homeland Security secretary and former White House chief of staff John Kelly, was one of the administration officials who privately resisted, or only reluctantly embraced, policies built around hard-line positions like this.

Miller has survived them all. He's the only permanent fixture on immigration policy. That means he's running the show — and the president's success or failure is on him.