The Supreme Court has sided with an immigrant convicted of residential burglary and facing deportation and found the term “crime of violence” was unconstitutionally vague.

The court ruled 5-4, with Justice Elena Kagan delivering the opinion. The justices affirmed a decision from the 9th U.S. Circuit Court of Appeals, which found in 2015 that a provision of federal immigration law subjecting immigrants to deportation if they are convicted of a “crime of violence” was too vague.

Justice Neil Gorsuch, nominated by President Trump and considered a member of the court’s conservative wing, cast the deciding vote by joining Justices Ruth Bader Ginsburg, Stephen Breyer, Sonia Sotomayor, and Kagan, who make up the court's liberal wing.

[Also read: Neil Gorsuch thrills conservatives in first year on Supreme Court]

Chief Justice John Roberts and Justices Clarence Thomas, Samuel Alito, and Anthony Kennedy dissented.

The justices heard the case last year, but deadlocked 4-4 after Justice Antonin Scalia’s death.

It was heard again on the first day of the term that began in October, indicating Gorsuch, the newest member of the court, would cast the deciding vote.

[Neil Gorsuch: Scalia's views on the Constitution aren't 'going anywhere on my watch']

James Garcia Dimaya, a lawful permanent resident who immigrated to the U.S. from the Philippines at 13, brought the case.

Dimaya was convicted of residential burglary in 2007 and 2009, though neither of the crimes involved violence. The Department of Homeland Security under the Obama administration, though, sought to deport Dimaya in 2010 after determining the crimes could be considered crimes of violence.

The Justice Department’s Board of Immigration Appeals agreed with the Obama administration’s conclusion that Dimaya should be deported, as one of the convictions constituted an “aggravated felony” and therefore made him subject to mandatory deportation.

But the 9th U.S. Circuit Court of Appeals disagreed and decided the definition of “aggravated felony” under the Immigration and Nationality Act, which incorporates the definition of “crime of violence,” was unconstitutionally vague.

The government then appealed the ruling to the high court.

With its ruling Tuesday, the Supreme Court handed the Trump Justice Department a defeat as the administration continues with its push to boost deportations of immigrants who commit crimes.

The Trump administration had defended the law, as the Obama administration did.

But in the opinion Tuesday, Kagan cited a 2015 8-1 Supreme Court decision, written by Scalia, that struck down a clause of the Armed Career Criminal Act as unconstitutionally vague in the opinion Tuesday.

That case, Kagan wrote, “tells us how to resolve this case.”

In his concurring opinion, Gorsuch explained the problem with the vastness of the definition of "crimes of violence."

“Before holding a lawful permanent resident alien like James Dimaya subject to removal for having committed a crime, the Immigration and Nationality Act requires a judge to determine that the ordinary case of the alien’s crime of conviction involves a substantial risk that physical force may be used. But what does that mean?” Gorsuch wrote.

“Just take the crime at issue in this case, California burglary, which applies to everyone from armed home intruders to door-to-door salesmen peddling shady products. How, on that vast spectrum, is anyone supposed to locate the ordinary case and say whether it includes a substantial risk of physical force? The truth is, no one knows. The law’s silence leaves judges to their intuitions and the people to their fate. In my judgment, the Constitution demands more.”

Correction: Due to an editor's error, the headline on this story incorrectly stated Dimaya was an illegal immigrant. He was in the U.S. legally.