In the past several days, Mr. Trump has forced out Kirstjen Nielsen, his homeland security secretary, and several other top immigration officials for being too timid about shutting down the border and changing asylum rules to deny entry to migrants seeking protection in the United States.

One of those officials, Ronald D. Vitiello, the acting chief of Immigration and Customs Enforcement, resigned on Wednesday after Mr. Trump pulled back his nomination for the permanent position, saying he wanted someone tougher. In a statement issued on her last day in office, Ms. Nielsen called Mr. Vitiello “an unwavering advocate for the dedicated men and women who enforce our immigration laws.”

A top administration official said Tuesday that the staffing changes were meant to make way for more aggressive immigration actions.

[Sign up for Crossing the Border, a limited-run newsletter about life where the United States and Mexico meet.]

But the president faces challenges of his own. His campaign promises have mostly gone unfulfilled. He has largely failed to build the “big beautiful wall” along the southwestern border as he promised. And the recent surge of migrant families from Central America is a vivid demonstration of his inability to stop what he has called an “invasion.”

There was also significant evidence during the 2018 midterm elections that the president’s immigration attacks backfired in some Republican districts around the country. For example, several House Republicans, including some of the party’s leaders in Congress, complained to Mr. Trump that his announcement right before the election that he was considering an executive order to end birthright citizenship might have cost several moderate Republicans their seats.

And as he sets out for the re-election campaign, Mr. Trump is certain to face several challengers among the Democrats who are determined to make the president’s immigration agenda a key part of their reason for running. In February, Beto O’Rourke, a former congressman from El Paso who has since declared his own candidacy for president, outlined his opposition to Mr. Trump’s immigration policies at a rally held at the same time the president spoke in that Texas border city.