President Donald Trump, under mounting political pressure from angry members of his own party, signed an executive order Wednesday reversing his administration's policy of separating children from their parents at the border and allowing families to instead be detained together.

"It's about keeping families together while ensuring we have a powerful border," Trump said.

Trump said the order "will solve that problem" of children being separated from their parents, but that it wouldn't end his administration's "zero tolerance" policy of charging everyone who attempts to cross the U.S.-Mexico border illegally. The practice has led to thousands of migrant children, some under a year old, being split from their parents or legal guardians and housed in detention centers.

"I didn't like the sight or the feeling of families being separated," Trump said.

The executive order won't stop the detention of children — or Trump's "zero tolerance" policy of charging people with a misdemeanor for entering the country illegally — but will allow them to be held with their parents pending "any criminal improper entry or immigration proceedings involving their members."

The order directs the agency to "prioritize" hearings for families in detention to speed up processing and also directs Attorney General Jeff Sessions to file a request in federal court to modify a longstanding federal court decree — known as the "Flores settlement" — that prohibits the government from holding children in detention for longer than 20 days.

Such a modification would allow DHS "to detain alien families together" throughout pending criminal proceedings for improperly entering the country or other immigration proceedings, according to the order.

The Alabama-based Southern Poverty Law Center said Trump's reversal still amounts to treating families like criminals by holding them in detention facilities.

A statement from the president of the organization, Richard Cohen, says there are other alternatives available. And it says indiscriminate enforcement is "shattering" communities across the country.

House Minority Leader Nancy Pelosi, D-Calif., said the order "seeks to replace one form of child abuse with another."

"Instead of protecting traumatized children, the president has directed his attorney general to pave the way for the long-term incarceration of families in prison-like conditions," Pelosi said in a statement.

Under the order, the Defense Department must also provide and, "if necessary," construct facilities to house and care for the families.

Defense Secretary Jim Mattis says the Pentagon will "respond if requested" to house migrants detained after crossing the U.S.-Mexico border illegally.

When a reporter noted that federal agencies have assessed four military bases for potential use as temporary housing for detained migrants, including unaccompanied children, Mattis said the Pentagon will "support whatever" the Department of Homeland Security says it needs. In the meantime, he said, this is not a matter for the Pentagon to comment on.

It remains unclear how the government will get around the immediate separations that occur when parents are charged with a crime and taken to court for entering the country illegally. But officials said they believe they have found a way to continue those charges without separating the children.

It also remains unclear how the administration will reunite the families that have already been separated at the border. In a call with reporters, a Department of Justice official referred questions about the children who are currently without their parents to the Department of Health and Human Services and the Department of Homeland Security.

The order marks an abrupt about-face for the president, who said as recently as Friday that when it came to keeping migrant families together, "you can't do it through executive order." He had faced extraordinary pressure from Capitol Hill, even from some of his closest GOP allies, as well as from members of his own family, to end his administration's policy of separating children from parents who cross the U.S.-Mexico border illegally.

Many Republicans have demanded an end to the policy, and at least two bills to halt it are under consideration in the House.

Pressure grew Tuesday night after The Associated Press reported that administration officials have been sending babies and other young children forcibly separated from their parents at the U.S.-Mexico border to at least three "tender age" shelters in South Texas.

First lady Melania Trump has also been a factor, a source familiar with the matter told NBC News. According the source, Mrs. Trump has been having private discussions behind the scenes in order to try to end the separation of kids and families at the border. Earlier this week, she uncharacteristically waded into the immigration debate, pushing for bipartisan cooperation to end the practice.

The House is set to vote Thursday on two immigration bills: a more conservative measure written by Rep. Bob Goodlatte, R-Va., chairman of the House Judiciary Committee, and a compromise measure.

Following Trump's remarks Wednesday, roughly two dozen House Republicans headed to the White House to discuss the measures.

Despite the order, Trump nevertheless doubled down on his hard-line stance on immigration, saying earlier in the day that he "likes to be strong" and that migrants were "using the children as a ticket to get into" the country.

Trump also announced that he'd canceled a congressional picnic that had been scheduled for Thursday, saying the timing "just didn't feel right."