The court's ruling allows 650,000 undocumented immigrants who arrived in the US as children to remain and work.
The US Supreme Court on Thursday dealt US President Donald Trump a major setback on his hardline immigration policies, ruling against his bid to end a programme that protects from deportation 650,000 immigrants, dubbed "Dreamers", who entered the United States as children without documentation.
The justices upheld lower court rulings that found that Trump's 2017 move to rescind the Deferred Action for Childhood Arrivals (DACA) programme, created in 2012 by his Democratic predecessor Barack Obama, was unlawful.
Those who receive relief through the plan are typically called "Dreamers" by advocates and commentators alike, after the US Congressional DREAM (Development, Relief, and Education for Alien Minors) Act legislation that took up their cause.
The US Department of Homeland Security (DHS) moved to end the programme in September 2017.
In its decision, the court wrote the "dispute before the Court is not whether DHS may rescind DACA. All parties agree that it may. The dispute is instead primarily about the procedure the agency followed in doing so."
However, the court concluded that the "total rescission" of DACA "was arbitrary and capricious".
For now, Dreamer immigrants retain their protection from deportation and their authorisation to work in the US.
When Trump's administration moved to end the act, protests were organised against the move across the country with Dreamers and advocates calling for new legislation that would provide a path to citizenship.
The programme grants deportation relief and work permits - but not a path to citizenship - to 649,000 immigrants brought to the US as children without documentation.
Trump lashed out at the Supreme Court decision and another on Monday that extended federal employment protections to gay and transgender workers under the 1964 Civil Rights Act.
He called the decisions "horrible and politically charged" and tweeted, "Do you get the impression that the Supreme Court doesn't like me?"
Democrat Senator Chuck Schumer, speaking at the US Capitol on Thursday, called the decision "surprising and welcome".
"Let me say this - in these very difficult times the Supreme court provided a bright ray of sunshine this week, with the decision on Monday ... and now with this decision," Schumer said.