Bowing to pressure from anxious allies, U.S. President Donald Trump abruptly reversed himself Wednesday and signed an executive order halting his administration's policy of separating children from their parents when they are detained illegally crossing the U.S. border.

It was a dramatic turnaround for Trump, who has been insisting, wrongly, that his administration had no choice but to separate families apprehended at the border because of federal law and a court decision.

The order does not end the "zero-tolerance" policy that criminally prosecutes all adults caught crossing the border illegally. But, at least for the next few weeks, it would keep families together while they are in custody, expedite their cases and ask the Defence Department to help house them. It also doesn't change anything yet for the some 2,300 children taken from their families since the policy was put into place.

The news in recent days has been dominated by searing images of children held in cages at border facilities, as well as audio recordings of young children crying for their parents — images that have sparked fury, questions of morality and concern from Republicans about a negative impact on their races in November's midterm elections.

'This is a stopgap measure'

Until Wednesday, the president, Homeland Security Secretary Kirstjen Nielsen and other officials had repeatedly argued the only way to end the practice was for Congress to pass new legislation, while Democrats said Trump could do it with his signature alone. That's just what he did.

Just days ago, U.S. President Donald Trump said it was up to Democrats to stop the practice of separating families at the border, arguing he couldn't change it by executive order. 0:45

"We're going to have strong, very strong borders, but we're going to keep the families together," said Trump, who added that he didn't like the "sight" or "feeling" of children separated from their parents.

Under a previous class-action settlement that set policies for the treatment and release of minors caught at the border, families can only be detained for 20 days. A senior Justice Department official said that hasn't changed.

"This is a stopgap measure," said Gene Hamilton, counsel to the attorney general. Justice lawyers were planning to file a challenge to the agreement, known as the Flores settlement, asking that a judge allow for the detention of families until criminal and removal proceedings are completed.

Fresh set of problems

So Trump's order is likely to create a fresh set of problems and may well spark a new court fight. It's unclear what happens if no changes to law or the settlement take place by the time families reach the detainment deadline. The language also leaves room to separate children from parents if it's best for the child's welfare.

And it didn't do much for the teeming outrage over the issue. The Alabama-based Southern Poverty Law Center said the order didn't go nearly far enough.

Here is the text of the executive order President Trump just signed: <a href="https://t.co/sM9e5aWWZR">https://t.co/sM9e5aWWZR</a> —@WhiteHouse

"The administration still plans to criminalize families — including children — by holding them in prison-like detention facilities. There are workable alternatives," president Richard Cohen said in a statement.

It's also unclear what will happen to the children already separated. Health and Human Services Secretary Alex Azar said his department will start reuniting detained immigrant children with their parents — but he made no specific commitment on how quickly that can be accomplished. And officials said the cases of the children already separated and turned over to their custody would proceed as usual.

Trump's family played role

Trump's family apparently played a role in his turnaround.

A White House official said Melania Trump had been making her opinion known to the president for some time that she felt he needed to do all he could to help families stay together, whether by working with Congress or acting on his own.

And daughter Ivanka Trump tweeted, "Thank you @POTUS for taking critical action ending family separation at our border."

Homeland Security Secretary Nielsen briefed lawmakers on Capitol Hill Wednesday, and those on the fence over pending immigration legislation headed to the White House to meet with Trump. Assessments for possible detention facilities at military bases have already been done in Texas and another is expected in Arkansas on Thursday.

'It never ends!'

Two people close to Nielsen said she was the driving force behind the turnabout that led to the new order keeping families together. Those people were not authorized to speak publicly and commented only on condition of anonymity.

One of them said Nielsen, who had become the face of the administration's policy, had little faith that Congress would act to fix the separation issue and felt compelled to act. She was heckled at a restaurant Tuesday evening and has faced protesters at her home.

Kirstjen Nielsen dining in Mexican restaurant is set upon by vocal group of people opposing the detention of migrant children 0:43

Trump had tweeted early Wednesday, before issuing his order: "It's the Democrats fault, they won't give us the votes needed to pass good immigration legislation. They want open borders, which breeds horrible crime. Republicans want security. But I am working on something - it never ends!"

The "zero tolerance" policy put into place last month moves adults to the custody of the U.S. Marshals Service and sends many children to facilities run by the Department of Health and Human Services.

2,300 minors separated from families

The policy had led to a spike in family separations in recent weeks, with more than 2,300 minors separated from their families at the border from May 5 through June 9, according to Homeland Security.

The Flores settlement, named for a teenage girl who brought the case in the 1980s, requires the government to release children from custody and to their parents, adult relatives or other caretakers, in order of preference. If those options are exhausted, authorities must find the "least restrictive" setting for a child who arrived without parents.

Karla, who didn't want her last name used, walks across the Paso Del Norte Port of Entry, where the U.S. and Mexico border meet, with her children to ask for asylum Wednesday in El Paso, Texas. (Joe Raedle/Getty Images)

Peter Schey, class-appointed counsel in the Flores case, said Wednesday there was nothing in the agreement that prevents Homeland Security officials from detaining children with their parents, "as long as the conditions of detention are humane and the child remains eligible for release, unless the child is a flight risk, or a danger to herself or others, or the child's parent does not wish the child to be released."

He said he was looking into whether the court could block deportation of parents until they have been reunited with their children, and whether it could force the Trump administration to reunite those separated.

'Not the way we do things in Canada'

In 2015, a federal judge in Los Angeles expanded the terms of the settlement, ruling that it applies to children who are caught with their parents as well as to those who come to the U.S. alone. Other recent rulings, upheld on appeal, affirm the children's rights to a bond hearing and require better conditions at the Border Patrol's short-term holding facilities.

In 2016, the 9th U.S. Circuit Court of Appeals ruled that child migrants who came to the border with parents and were held in custody must be released. The decision did not state parents must be released. Neither, though, did it require parents to be kept in detention, apart from their children.

Democrat congressman Juan Vargas of California protests outside the meeting where Trump met with Republicans on Tuesday. (Alex Edelman/AFP/Getty Images)

Prime Minister Justin Trudeau, who declined an opportunity to criticize the U.S. shift earlier this week, was emphatic in condemning the practice on Wednesday.

"What's going on in the United States is wrong," he said. "I can't imagine what the families living through this are enduring. Obviously, this is not the way we do things in Canada."