The Supreme Court has rejected Donald Trump's effort to end legal protections for 650,000 young immigrants.
The ruling means the young immigrants, known as Dreamers, retain their protection from deportation and their authorisation to work in the US.
The 5-4 outcome, in which Chief Justice John Roberts and the four liberal justices were in the majority, seems certain to elevate the issue in Mr Trump's campaign, given the anti-immigrant rhetoric of his first presidential run in 2016 and immigration restrictions his administration has imposed.
The justices rejected administration arguments that the eight-year-old Deferred Action for Childhood Arrivals Programme is illegal and that courts have no role to play in reviewing the decision to end DACA.
The programme covers people who have been in the United States since they were children and are in the country illegally. In some cases, they have no memory of any home other than the US.
Pictures of the week: June 14 - June 20
Pictures of the week: June 14 - June 20
A woman wearing a facemask walks past a large rainbow in Covent Garden, London, after the UK's chief medical officers agreed to downgrade the coronavirus alert level from four to three after a "steady" and continuing decrease in cases in all four nations.
The Red Arrows and the Patrouille de France flypast over Nelson's Column in London to mark the visit of President of the Republic of France Emmanuel Macron. (Photo by Dave Rushen / SOPA Images/Sipa USA)
Bianca Walkden during the training session at the National Taekwondo Centre, Manchester. (Photo by David Davies/PA Images via Getty Images)
Larry, the No 10 Downing Street cat and Chief Mouser to the Cabinet Office out and about in Downing Street. (Photo by Brett Cove / SOPA Images/Sipa USA)
French President Emmanuel Macron meets Prince Charles, Prince of Wales and Camilla, Duchess of Cornwall during a ceremony at Carlton Gardens. The French president is visiting London on June 18, 2020 to commemorate the 80th anniversary of Charles de Gaulle's BBC broadcast to occupied France following the Nazi invasion in 1940 "Appel" .
Police restrain a demonstrator who ran after Emmanuel Macron’s car convoy as a protest against French interference in Cameroon domestic affairs. The French president was attending an official event with British Prime Minister Boris Johnson during his visit to the UK to mark the 80th anniversary of French Resistance leader Charles de Gaulle’s wartime broadcast. Picture date: Thursday June 18, 2020.
A bear plays in a pool as four European brown bears and five grey wolves which are living together in British woodland for the first time in Bear Wood, a new enclosure at Bristol Zoo's Wild Place project. (Photo by Ben Birchall/PA Images via Getty Images)
Steven Butterly from Azurablu Scotland Ltd during an electrostatic disinfection clean which follows a deep clean at Ross Sales and Lettings in Glasgow. (Photo by Andrew Milligan/PA Images via Getty Images)
BIRMINGHAM, ENGLAND - JUNE 17: Black Lives Matter writing is seen on the back of Ollie Norwood and Billy Sharp of Sheffield United shirts during the Premier League match between Aston Villa and Sheffield United at Villa Park on June 17, 2020 in Birmingham, England. (Photo by Shaun Botterill/Getty Images)
LONDON, ENGLAND - JUNE 17: Workers uncover the statue of Winston Churchill in Parliament Square on June 17, 2020 in London, United Kingdom. The statue was covered up to protect it from vandalism over the weekend, after it was targeted by Black Lives Matter protesters. It is being uncovered ahead of French President Emmanuel Macronâs visit the UK to commemorate the 80th anniversary of Charles de Gaulleâs speech urging the French population to resist German occupation during World War II. (Photo by Ilyas Tayfun Salci/Anadolu Agency via Getty Images)
A protestor holds a placard depicting Dominic Cummings, Special Political Advisor for the Prime Minister Boris Johnson, as pro-EU supporters demonstrate outside Houses of Parliament against no-deal Brexit and call for an extension of the transition period on 17 June, 2020 in London, England. The EU and the UK are negotiating the post-Brexit relationship as Britain's transition period ends in December. (Photo by WIktor Szymanowicz/NurPhoto via Getty Images)
MANCHESTER, ENGLAND - JUNE 17: The Arsenal and Manchester City players minutes silence before the Premier League match between Manchester City and Arsenal FC at Etihad Stadium on June 17, 2020 in Manchester, England. (Photo by David Price/Arsenal FC via Getty Images)
A man walks past a mural of Malcom X and Martin Luther King paying tribute to George Floyd, a Black man who died in police custody in the U.S. Artists have been painting murals and sharing messages in London. (Photo by Thabo Jaiyesimi / SOPA Images/Sipa USA)
ASCOT, ENGLAND - JUNE 17: Frankie Dettori in The Queens silks prior to the Hampton Court Stakes during Day 2 of Royal Ascot at Ascot Racecourse on June 17, 2020 in Ascot, England. (Photo by Edward Whitaker/Pool via Getty Images)
Florist Trish Collins-Morgan works behind a plastic screen as she re-opens her shop, with various safety policies in place, in West Kirby north west England on June 17, 2020, as lockdown restrictions are eased during the novel coronavirus COVID-19 pandemic. - Various stores and outdoor attractions in England opened Monday for the first time in nearly three months, as the government continues to ease its coronavirus lockdown. (Photo by Paul ELLIS / AFP) (Photo by PAUL ELLIS/AFP via Getty Images)
Members of Kurdish Community Scotland during a demonstration in Edinburgh protesting against Turkish air raids in Iraq. (Photo by Jane Barlow/PA Images via Getty Images)
A pro-Kurdish protester who ran into the road toward the car of Britain's Prime Minister Boris Johnson as it was leaving the Houses of Parliament in London on June 17, 2020 is led away by police officers. - The protester ran into the road towards the Jaguar that normally carries the Prime Minister Boris Johnson and was stopped by police. As the Jaguar stopped it was subsequently struck from behind by the next vehicle in the convoy resulting in a large dent. (Photo by DANIEL LEAL-OLIVAS / AFP) (Photo by DANIEL LEAL-OLIVAS/AFP via Getty Images)
MILTON KEYNES, UNITED KINGDOM - 2020/06/15: A couple walk past the Victoria's Secret store.
Non essential shops were reopened today in both the 'Intu Shopping Centre' and the 'centre:mk' in Milton Keynes, for the first time since the coronavirus (Covid-19) pandemic lockdown. Social distancing measures were in place for all stores, including a one way system for shoppers and plenty of queuing around both shopping centres. (Photo by Keith Mayhew/SOPA Images/LightRocket via Getty Images)
LONDON, UNITED KINGDOM - 2020/06/15: A woman in a facemask walks over Waterloo Bridge.
Secretary of State for Transport Grant Shapps, announced that all passengers must wear face masks on public transport starting from 15 June and warned that wearing of a face mask would be a condition for travel and failure to comply will result either in not being allowed to travel or a fine. (Photo by Dave Rushen/SOPA Images/LightRocket via Getty Images)
Rubbish left by a bus stop at the end of lockdown on 15th June in Southampton Row, London, United Kingdom. (photo by Barry Lewis/InPictures via Getty Images)
An employee at Top Gift Mobile stall wears a face shield and mask as preventive measure while working. (Photo by Dawn Fletcher-Park / SOPA Images/Sipa USA)
A customer carrying bags of shopping leaves Primark in Birmingham as non-essential shops in England open their doors to customers for the first time since coronavirus lockdown restrictions were imposed in March. (Photo by Jacob King/PA Images via Getty Images)
(Permission granted) A school pupil wearing a face mask on a bus in Newcastle as face coverings become mandatory on public transport in England with the easing of further lockdown restrictions during the coronavirus pandemic. (Photo by Owen Humphreys/PA Images via Getty Images)
Loyalist Defence League members gather in George Square in Glasgow, Sunday June 14, 2020, during a protest between people calling for the removal of a statue Robert Peel and counter protesters. (Jane Barlow/PA via AP)
LONDON, ENGLAND - JUNE 14: A view of the closed Music Venue, Electric Ballroom, on June 14, 2020 in London, UK .As the British government further relaxes Covid-19 lockdown measures in England, this week sees preparations being made to open non-essential stores and Transport for London handing out face masks to commuters. International travelers arriving in the UK will face a 14-day quarantine period. (Photo by Jo Hale/Getty Images)
Passengers wearing face masks at Waterloo station in London as face coverings become mandatory on public transport in England with the easing of further lockdown restrictions during the coronavirus pandemic. (Photo by Victoria Jones/PA Images via Getty Images)
A man walks past a Be kind. Let's look out for one another poster in London. (Photo by Dinendra Haria / SOPA Images/Sipa USA)
Barriers seen packed outside a property in north London. (Photo by Dinendra Haria / SOPA Images/Sipa USA)
Police officers wearing face masks at Leeds railway station as face coverings become mandatory on public transport in England with the easing of further lockdown restrictions during the coronavirus pandemic. (Photo by Danny Lawson/PA Images via Getty Images)
LONDON, ENGLAND - JUNE 14: Social Distancing Signs on the Cobbles of Camden Market on June 14, 2020 in London, UK .As the British government further relaxes Covid-19 lockdown measures in England, this week sees preparations being made to open non-essential stores and Transport for London handing out face masks to commuters. International travelers arriving in the UK will face a 14-day quarantine period. (Photo by Jo Hale/Getty Images)
Discover More Like This
BACK TO SLIDE
Trump did not hold back in his assessment of the court's work, hitting hard at a political angle.
"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!" he wrote on Twitter.
In a second tweet, he wrote, "Do you get the impression that the Supreme Court doesn't like me?"
Mr Roberts wrote for the court that the administration did not pursue the end of the programme properly.
"We do not decide whether DACA or its rescission are sound policies," Mr Roberts wrote. "We address only whether the agency 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, he wrote. But any new order to end the programme, and the legal challenge it would provoke, would likely take months, if not longer.
"No way that's going to happen before November," said Stephen Yale-Loehr, a professor of immigration law practice at Cornell University Law School.
The court's four conservative justices dissented.
Justice Clarence Thomas, in a dissent joined by Justices Samuel Alito and Neil Gorsuch, wrote that DACA was illegal from the moment it was created under the Obama administration in 2012. Mr Thomas called the ruling "an effort to avoid a politically controversial but legally correct decision".
Mr Alito wrote that federal judges had prevented DACA from being ended "during an entire Presidential term. Our constitutional system is not supposed to work that way".
Justice Brett Kavanaugh wrote in a separate dissent that he was satisfied that the administration acted appropriately in trying to end the programme.
DACA recipients were elated by the ruling.
"We'll keep living our lives in the meantime," said Cesar Espinosa, who leads the Houston immigration advocacy group FIEL. "We're going to continue to work, continue to advocate."
Mr Espinosa said he got little sleep overnight in anticipation of a possible decision on Thursday. In the minutes since the decision was posted, he said his group was "flooded with calls with Dreamers, happy, with that hope that they're going to at least be in this country for a while longer".
From the Senate floor, the 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."