The U.S. Supreme Court has rejected the Trump administration’s move to end DACA, a ruling that at least for now protects the collective futures of hundreds of thousands of younger undocumented immigrants who have built lives and careers in America.

In a 5-4 decision issued Thursday, the justices turned away administration arguments that the eight-year-old Deferred Action for Childhood Arrivals Program is illegal and that courts have no role to play in reviewing the decision to end it.

The ruling seems to settle one of the most consequential immigration cases of the Trump era: whether DACA was legally created by President Barack Obama.

Chief Justice John G. Roberts Jr., joined by the court’s four liberals, wrote for the majority that the administration did not properly end the program, failing to provide adequate reason and justification.

“We do not decide whether DACA or its rescission are sound policies,” Roberts wrote in the decision. “We address only whether the agency [the Department of Homeland Security] complied with the procedural requirement that it provide a reasoned explanation for its action. Here the agency failed to consider the conspicuous issues of whether to retain forbearance and what if anything to do about the hardship to DACA recipients.”

The Department of Homeland Security can try again to kill the program, Roberts wrote. However, immigration experts say that would provoke legal challenges sure to go on for months or longer.

A permanent solution could come from Congress, which has long failed to act on comprehensive immigration reform, including DACA.

”Do you get the impression that the Supreme Court doesn’t like me?” President Donald Trump tweeted Thursday morning, just three days after the court rebuked the administration by ruling that it is illegal to fire people because they’re gay or transgender. “These horrible & politically charged decisions coming out of the Supreme Court are shotgun blasts into the face of people that are proud to call themselves Republicans or Conservatives. We need more Justices or we will lose our 2nd. Amendment & everything else. Vote Trump 2020.”

The DACA ruling affects some 700,000 immigrants who as children were illegally brought into the country by their parents. Known as “Dreamers,” DACA recipients get no citizenship or legal status, but may attend college and obtain work permits and renewable, two-year deferments from deportation. Under the Trump administration’s plan to end the program, the recipients — including an estimated 27,000 doctors, nurses, technicians, and aides treating coronavirus patients during the pandemic — were facing possible deportation. Thursday’s decision leaves all DACA protections in place and says that the administration must resume accepting new applications.

“I think this is long overdue,” said DACA recipient Jonatan Quintino Juarez, 23, a medical assistant at Penn Medicine Lancaster General Health. “The court, just like many Americans, side with us on this issue and know the vulnerability.... I’m very happy to see that court has sided with Dreamers and has allowed Trump to see that he can’t just do and undo people’s lives like that.”

Others were not as encouraged.

“I don’t want to sound pessimistic,” said Mariana Galati, 27, of South Jersey, a registered medical assistant at Jefferson Health, but “today’s decision can be disrupted again. I still don’t feel assured about my future. This is still an uphill battle for me with no end in sight. How much more do I have to prove myself to be accepted?”

Amid physician shortages and surging caseloads, DACA recipients have provided vital patient care, said Susan Bailey, president of the American Medical Association, adding that ending the program would have reduced the nation’s health-care capacity at a critical time.

“Waking up to this news was such a relief!” said Louise Rogenski, a CT technlogist who scans patients at Jeanes Campus of Temple University Hospital. “However, it is only the beginning. … I think now is a good time to come up with a more permanent solution. For most DACA recipients, including myself, the U.S. is the only country we know.”

Philadelphia Mayor Jim Kenney tweeted: “Today’s Supreme Court ruling is a huge victory for our country. Philadelphia stands with DACA recipients, who contribute to our progress and our communities. Dreamers: We respect you, we love you, and we will continue fighting for you.”

A new Morning Consult/Politico poll shows nearly two-thirds of voters believe DACA recipients should be allowed to stay in the United States and be given a pathway to citizenship. That includes 61% of Democrats, 60% of independents, and 46% of Republicans.

Only 12% of voters believe DACA-holders should be deported.

“The Trump administration may continue its bigoted and politically motivated attacks on DACA, and may continue to ramp up enforcement and infuse more cruelty into our immigration system, but [today’s] decision makes it increasingly clear that justice is on our side,” the National Immigration Law Center in Los Angeles tweeted, adding the hashtags #HomeIsHere and #ImmigrantsAreEssential.

From the Senate floor, Democratic leader Chuck Schumer said of the DACA decision, “I cried tears of joy.”

“Wow,” he went on, choking up. “These kids, these families, I feel for them, and I think all of America does. The outcome seems certain to elevate the issue in Trump’s reelection campaign, given the strong anti-immigrant rhetoric of his first presidential run in 2016 and the many restrictions on immigration he has imposed since then.”

Trump ended Deferred Action for Childhood Arrivals in 2017, and fought the legal rulings that have kept it alive all the way to the Supreme Court. The lower-court decisions have allowed Dreamers to continue filing for renewals, although acceptance of new applications had been halted. DACA opponents say Obama had no authority to create the program without congressional approval, and that immigration laws must be enforced without exceptions.

In Thursday’s ruling, Roberts was joined by Ruth Bader Ginsburg, Stephen G. Breyer, Sonia Sotomayor, and Elena Kagan. Four conservative justices dissented: Clarence Thomas, Samuel A. Alito Jr., Neil M. Gorsuch, and Brett M. Kavanaugh.

Calling the program “illegal,” Thomas wrote that the court “has given the green light for future political battles to be fought in this court rather than where they rightfully belong,” in Congress.

“Dreamers across the country, and those who love and depend on them, are breathing a sigh of relief,” said Ben Johnson, executive director of the national American Immigration Lawyers Association. “Despite this great news, and our exhilaration about the decision, the court has made clear that the president has both the power to continue the program and the power to terminate if he follows the correct legal process. For the sake of not only Dreamers but our nation, this legal limbo must end.”

This article contains information from the Associated Press.