(CNN) President Donald Trump on Wednesday reversed his debunked argument that he had no authority to stop separations of undocumented immigrant families at the border, signing an executive order to keep parents and kids together.

"We're signing an executive order. I consider it to be a very important executive order. It's about keeping families together, while at the same time being sure we have a very powerful, very strong border," Trump said.

Trump's climbdown came after he faced intense pressure from across the political spectrum and from religious, political and world leaders to halt the separations, which produced days of heartrending news coverage of crying children -- some of whom were kept in cage-like detention centers.

The President claimed, though, that he isn't backing down.

"The border is just as tough. But we do want to keep families together," Trump said in the Oval Office. "We are keeping the family together."

Earlier Wednesday after a frenzied morning in which he huddled with Homeland Security Secretary Kirstjen Nielsen and other key officials, Trump first flagged his reversal saying, "I'll be doing something that's somewhat preemptive and ultimately will be matched by legislation I'm sure."

Just the day before, Trump had claimed his administration's hands were tied without congressional action.

"Under current law, we have only two policy options to respond to this massive crisis. We can either release all illegal immigrant families and minors who show up at the border from Central America or we can arrest the adults for the federal crime of illegal entry. Those are the only two options, totally open borders or criminal prosecution for law-breaking," the President had said.

By Wednesday morning, he had changed course.

In the executive order he signed on Wednesday, Trump declared it is his administration's policy to "maintain family unity," including by detaining entire families together "where appropriate and consistent with law and available resources."

The order directs other agencies, including the Pentagon, to take steps to find places to house family units.

The order specifies that migrants entering the US with children will not be kept together if there's a fear for the child's welfare. Families will also be prioritized in the adjudication process.

Even so, the move is almost certain to face immediate legal action challenging the administration's authority to keep families detained at length.

The President was not required to sign anything to change the administration's practice that elicited outrage. He could have reversed the practice of splitting children from their parents with a phone call.

Executive orders typically require input from the Office of the Legal Counsel. The details of the executive order were worked out between the White House, the Justice Department and the Department of Homeland Security, a source said.

The White House may run into legal difficulties if the executive order requires families to be held intact together indefinitely since a federal consent decree known as the Flores settlement says children must be released after 20 days.

Reversal

Trump's decision to relent was a reversal since he had gambled that he could use the plight of the children and public outrage to ram through his hardline changes to immigration police in legislation.

The President continued to use tough immigration rhetoric even on Wednesday though, signaling that he is not softening his desire to change the country's laws more broadly.

"The dilemma is that if you're weak, if you're weak, which some people would like you to be, if you're really, really pathetically weak, the country's going to be overrun with millions of people," Trump said.

"And if you're strong, then you don't have any heart. That's a tough dilemma. Perhaps I would rather be strong, but that's a tough dilemma," he said.

Trump also postponed Thursday's congressional picnic at the White House, an event that is always keenly awaited by lawmakers and their families, saying it didn't feel right.

The President's decision came a day after he met Republican lawmakers on Capitol Hill who fear that their own political prospects with the midterm elections are being damaged by the separation policy.

Democrats welcomed Trump's apparent change of course but said he had only himself to blame.

"The President is the one that created this humanitarian crisis," Texas Democratic Rep. Joaquin Castro told CNN's Wolf Blitzer.

"I hope the President will fix the problem that he created."

Crafting the order

While Attorney General Jeff Sessions was not at the meeting at the White House Wednesday morning, his chief of staff has been there to represent the Justice Department, the source added.

Prior to Trump's remarks, White House aides refused to comment on rumors of an executive order and Republicans on Capitol Hill seemingly had no knowledge of a coming executive action. Until now, Trump and White House officials have instead been pushing GOP lawmakers this week to pass legislation that deals with immigration reform.

The move -- if it retreats from his current stance that the administration is simply following the current law and needs congressional action to stop the separations -- would mark a huge reversal by the President.

Both first lady Melania Trump and Nielsen reportedly had roles in the changing course.

The first lady has been working for several days behind the scenes, encouraging the President to keep families together, a White House official told CNN. She has had several private conversations with her husband, pushing him to do all he can to keep families at the border intact, whether via a legislative route, or acting alone to stop the process, the official said.

The shift in Trump's thinking came an hour after Speaker Paul Ryan said the House would vote Thursday on a compromise between conservative and moderate Republican lawmakers that would address the issue of family separations.

The measure would also offer protections to another vulnerable group -- Deferred Action for Childhood Arrivals recipients -- who are undocumented immigrants brought to the US as children.

But the chances of the bill passing are unclear as is the case with any bill dealing with the volatile issue of immigration. The fact that it includes fundamental changes to the legal immigration system mean its chances in the Senate are even more uncertain.