But Trump’s frustration with Noem had been clear for months if not longer. The administration faced a major backlash for its immigration crackdown in Minneapolis in January, after federal agents shot dead two US citizens.

Trump sent White House border tsar Tom Homan, external to Minneapolis to lead the response, which resulted in a decision to scale back the operation. Homan’s appointment was widely viewed as a rebuke to Noem, who might normally have been given the assignment.

Noem was also criticised for comments she made after the deaths of Renee Good and Alex Pretti in Minneapolis, particularly her claim, made without evidence, that Pretti had “committed an act of domestic terrorism” before he was shot.

The deployment of Homan to take charge in Minnesota was a clear indication that Trump was sidelining Noem after giving her the freedom to act as the administration’s immigration enforcement star.

The administration response to the killings of Good and Pretti in Minneapolis was a rare instance of Trump moderating his message on immigration – and a sign the White House was aware the hardline approach spearheaded by Noem was growing unpopular with the public.

Polls have indicated that a majority of Americans approve of some aspects of Trump’s immigration agenda, but do not support the more aggressive tactics used by immigration agents in the field. That presents an issue for Republicans heading into an election year, and Noem’s removal suggests Trump saw a need to make a change.

It is also the first major shakeup of Trump’s second-term cabinet.

In his first term, Trump replaced his national security adviser, White House chief of staff and other top officials in his first year in office, oftentimes by announcing the firing in a tweet. The turmoil in his team frequently overshadowed Trump’s policies.

By contrast, Trump has kept his cabinet largely intact in his second term, avoiding the drama that engulfed his first stint in the White House. Whether Noem’s departure means others will follow remains to be seen.

It is also an open question whether the shakeup will lead to a new direction in policy at the Department of Homeland Security.

Mullin is a conservative Trump ally, and like Noem has long been a hardline immigration voice on the right. After Pretti’s shooting Mullin said federal law enforcement officials were “patriots” facing death threats for doing their job.

“Obstructing federal law enforcement is a felony. Most Americans follow ICE instructions without thinking twice,” Mullin said in a social media post.

More recently, he has criticised Democrats over a partial government shutdown of the Department of Homeland Security. The agency has been caught in a funding battle over proposed reforms to immigration enforcement.

In a scene reminiscent of Trump’s first term, Noem was delivering a speech in the moments when Trump posted his social media message announcing her firing. She soon published a social media post of her own, thanking Trump for her new role.

Noem may be the first high-profile casualty of Trump’s second term. But she may not be the last, as her demotion shows the president remains willing and able to read the political winds and cut his losses early.