President Trump is preparing to issue an executive order as soon as Wednesday that ends the separation of families at the border by indefinitely detaining parents and children together, flouting a court settlement that prohibits that move, according to a person familiar with the White House plans.

Stories of children being taken from their parents and images of teenagers in cage-like detention facilities have exploded into a full-blown political crisis for Mr. Trump and Republican lawmakers, who are desperate for a response to critics who have called the practice “inhumane” and “evil.”

Mr. Trump has for weeks refused to simply end his government’s “zero tolerance” policy that led to the separation of more than 2,300 children from their parents, saying that the alternative would be to fling open the nation’s borders and allow immigrants who cross the border illegally to remain in the country.

But the president, furious about the pummeling he has taken in recent days, has been casting about for an escape from the crisis, people familiar with his thinking said. Officials at the Department of Homeland Security are preparing the executive order that is designed to end the family separations.