The Supreme Court on Monday struck down a federal law allowing prosecutors to seek stiffer prison sentences for individuals convicted of committing certain crimes involving guns.

In a 5-4 decision, Justice Neil Gorsuch wrote the opinion for the majority, joining the court’s four liberal justices, while Justice Brett Kavanaugh wrote the dissenting opinion and joined the court’s three other conservatives.

The law examined by the court was passed in 1984 as part of a broad revision of the federal criminal statute, and authorized heightened penalties for federal defendants who use or possess a gun while committing a “crime of violence or drug trafficking crime.” Under the law, a defendant can get an additional five years for possessing a gun during a crime, seven years for brandishing a firearm, and 10 years for discharging the weapon. But a majority of court justices argued that the law was written so vaguely as to make it unclear which criminal offenses would be covered by the statute.

“In our constitutional order, a vague law is no law at all,” Gorsuch wrote in his opinion.

The court’s decision sided with defendants Maurice Davis and Andre Glover, who were convicted of a string of armed robberies targeting Texas gas stations in 2014. Both men were charged with robbery, conspiracy, and brandishing a shotgun. Davis was sentenced to 41 years in prison and Glover to more than 50 years.

In his opinion, Gorsuch wrote that the text of the law “provides no reliable way to determine which offenses qualify as crimes of violence and thus is unconstitutionally vague.” While the majority said there was no question that the robberies Glover and Davis committed were violent, they questioned whether the conspiracy charge entailed a risk of violence.

Gorsuch and the majority found that the law required judges and juries to impose a penalty not based on the actual facts of a given case, but rather on an understanding of an entire category of criminal conduct. As a result, the majority argued, courts under the law had to make sometimes arbitrary determinations about the classification of crime, including whether robberies or conspiracies in general always involved a substantial risk of violence.

The government unsuccessfully argued that prosecutors could apply the law to a defendant’s specific history and personality in a case without having to make broader categorical determinations about the nature of specific criminal activities.

In his dissent, Kavanaugh agreed with this view, noting that there are numerous other precedents in which the court affirmed the constitutionality of laws that allow judges and juries to consider the potential risk that criminal conduct could lead to violence when imposing a criminal penalty.

“That kind of risk-based criminal statute is not only constitutional, it is very common,” Kavanaugh wrote.

In light of Monday’s decision, a lower court must now determine whether to reduce Glover and Davis’s prison term on the conspiracy charge or completely resentence the two. Thousands of other inmates may also be eligible to have their sentences reduced.