The U.S. Supreme Court ruled Thursday against the Trump administration’s attempt to end the Deferred Action for Childhood Arrivals, which allowed non-citizens brought to this country illegally as children to apply for protection from deportation.

In a 5-4 ruling written by Chief Justice John Roberts, the Supreme Court said the government’s justification for ending the federal program was “arbitrary and capricious.” Roberts was joined by the court’s more liberal voices, Justices Ruth Bader Ginsburg, Elena Kagan, Stephen Breyer and Sonia Sotomayor.

In his majority opinion, Roberts wrote, “Whether DACA is illegal is, of course, a legal determination, and therefore a question for the Attorney General. But deciding how best to address a finding of illegality moving forward can involve important policy choices, especially when the finding concerns a program with the breadth of DACA. Those policy choices are for DHS.”

DACA, which was announced by the Obama White House in 2014, protected hundreds of thousands of immigrant children, known as “Dreamers,” to apply for temporary status that allows them stay and work in the U.S. without fear of deportation. It has granted some 700,000 people work authorization and various federal benefits.

Immigration has been a focal point of President Donald Trump’s domestic policy. He won the White House in 2016 after running on a platform that called for building a wall with Mexico, making it harder for people to immigrate to the U.S., and rounding up and deporting illegal immigrants.

Barack Obama wrote Thursday on Twitter, “Eight years ago this week, we protected young people who were raised as part of our American family from deportation. Today, I’m happy for them, their families, and all of us. We may look different and come from everywhere, but what makes us American are our shared ideals.

He continued, “And now to stand up for those ideals, we have to move forward and elect Joe Biden and a Democratic Congress that does its job, protects DREAMers, and finally creates a system that’s truly worthy of this nation of immigrants once and for all.”

This ruling marks the second time this week that the Supreme Court has sided with its liberal wing, something of a surprise given its rightward lurch in recent years. On Monday, in a major victory for the LGBTQ community, the Supreme Court said people cannot be discriminated against on the basis of sexual orientation or gender identity.