President Donald Trump signed an executive order on Wednesday halting his administration’s separation of immigrant families, putting an end to a practice that caused international outrage and rare condemnation from both parties in Washington.

The order will keep parents and children detained together while they await deportation. Due to the high backlog of asylum cases, those detentions could be indefinite.

It’s a reversal for Trump, who said last week, “we can’t do it through an executive order.”

Thousands of children have been separated from their parents since April, when the administration implemented a “zero tolerance” policy for people entering the U.S. illegally. (That policy continues under Trump’s order.) The separations became highly visible this week after lawmakers and reporters revealed that adults and children were being kept in cages in facilities in southern Texas. Elsewhere, children as young as a few months old were reportedly being held.

“I didn’t like the sight or the feeling of families being separated,” Trump said after signing the order.

It will likely create a new round of political and legal issues for the administration. The policy is expected to allow U.S. immigration agents to detain children with their families while the parents undergo criminal deportation proceedings. That could violate a 1997 court order that bars the federal government from detaining the children of illegal immigrants, and Trump’s move will likely be met by court challenges, a top Republican senator predicted.

On Capitol Hill, a successful legislative fix has become increasingly uncertain as Republicans and Democrats argue over tactics and policy, despite agreeing that the family-separation practice should end. In the wake of the executive order, Democrats immediately took issue with the idea that the detentions of immigrant families could be indefinite.

“Where in this country do we detain children and their parents for weeks or months pending trial? Where do we do that? How is that a good idea?” Sen. Chris Coons (D-DE) said. “It would be less harmful than wrenching young children away from their parents with no idea when they might be united. It is still inappropriate to warehouse children and their parents in detention centers.”

Trump’s order comes after several days of contradictory and false claims from the White House about the policy, claiming it is the law that families must be separated. On Monday, Trump said, “the Democrats have to change their law. That’s their law.” On Tuesday, Homeland Security Secretary Krisjen Nielsen said, “this administration did not create a policy of separating families at the border.” On Wednesday, Trump said he would sign an order that would end the policy before signing a new law that Congress could send to his desk.

The policy was implemented on April 6 when Attorney General Jeff Sessions announced that the Justice Department would criminally prosecute all adults entering the country illegally. Upon being detained by DHS, adults were referred to the Justice Department for criminal prosecution while minors were transferred to the Department of Health and Human Services to be held in detention facilities and, later, foster homes.

Trump’s announcement came a day after a closed-door meeting with House Republicans, where Trump voiced concerns about the political toll the controversy was exacting on his administration and his party. He told lawmakers that his daughter and adviser, Ivanka Trump, had asked him to find a way to end the family-separation practice.

Republicans, too, were worried about the optics surrounding the crisis, but were concerned on Wednesday that the president was acting in the interest of politics rather than policy. Many GOP lawmakers had adopted Trump’s view that it was up to the legislative branch to address the family-separation issue. After Wednesday’s executive order, they had little faith that Congress would work together without having a sense of urgency.

“It’ll take the heat off of Congress and you’re still going to have the uncertainty because future presidents can do otherwise,” Sen. Chuck Grassley (R-IA) said. “And we ought to have permanency, some predictability to it. It takes care of a political problem but it doesn’t take care of a policy problem.”

When asked if he still expects Congress to act, Grassey responded: “No. It takes the heat off. And that’s too bad.”

But Senate Majority Whip John Cornyn (R-TX) said lawmakers would still press forward with legislation because the president’s executive order could be subject to court challenges.

“What the president's trying to do is make sure that they’re kept together pending hopefully an expedited hearing in front of an immigration judge,” Cornyn said in an interview. “But I would not be surprised if there’s litigation about the executive order, which means that we still need to do the legislation.”

A group of 27 Senate Republicans introduced legislation on Wednesday that would address the family separations in addition to providing funding for more immigration judges and detention space. Those measures were aimed at lessening the backlog of asylum cases.

Cornyn’s effort needs Democratic support in order to clear the 60-vote threshold in the Senate. Cornyn said his group was talking with Sen. Dianne Feinstein (D-CA), who authored a bill that only addresses the family-separation aspect and has the support of all 49 Senate Democratic caucus members.

“Sen. Feinstein is a force of nature, and I hope she prevails because we need to get this solved,” Cornyn said.

A senior White House aide, who asked to remain anonymous to speak candidly, said those political considerations led to Trump’s reversal on Wednesday.

It’s “pretty clear this isn’t going away,” the aide said, “and [Senate Minority Leader Chuck] Schumer’s happy to squeeze every vote he can out of it, so at a certain point the reality of the optics and politics sets in. Might as well rip off the band-aid.”