An appeals court ruled Tuesday that the U.S. Department of Justice can’t prosecute medical marijuana patients and providers for violating federal cannabis law as long as those individuals are in full compliance with state laws legalizing medical marijuana.

A three-judge panel of the U.S. Court of Appeals for the 9th Circuit held unanimously that a 2014 budget measure “prohibits DOJ from spending funds” to go after such people.

That’s bad news for the Justice Department’s increasingly controversial war on marijuana. Currently, 25 states and the District of Columbia have legalized the drug for medical purposes.

In the 10 cases from California and Washington state before the court, the 9th Circuit ruled that the Justice Department must show that the defendants were in violation of their state marijuana laws before proceeding with the federal criminal prosecutions. The appeals court sent all 10 cases back to the trial courts to make such determinations.

But Judge Diarmuid O’Scannlain, writing for the court, pointed out the precarious nature of the federal block on these prosecutions. In a footnote, he said that “Congress could restore funding tomorrow, a year from now, or four years from now, and the government could then prosecute individuals who committed offenses while the government lacked funding.”

The judge also noted that the next administration may “shift enforcement priorities” and place a greater emphasis on prosecution of federal marijuana crimes.

Nonetheless, “this really is a big deal,” said Sam Kamin, a professor at the University of Denver’s Sturm College of Law who studies marijuana regulation.

“It’s an assertion by a court ― the largest federal circuit ― that federal prosecutors cannot enforce the Controlled Substances Act against those in compliance with state medical marijuana provisions,” he explained. “It’s not forever ... but it’s a lot more protection than was in place prior to the ruling.”

Kamin added that the panel’s unanimity shouldn’t give the Obama administration “much reason for optimism,” should it choose to appeal.

Tom Angell, chairman of the drug policy reform group Marijuana Majority, was similarly exuberant.

“If the Obama administration is smart, they’ll drop this fight right now rather than risk an even more embarrassing defeat on appeal,” he told HuffPost.

DOJ spokesman Peter Carr told HuffPost that the department was reviewing the decision and declined further comment.

The defendants in the 10 cases had argued that the charges should be dismissed because of a bipartisan budget measure, passed in December 2014, that bars the Justice Department from using federal funds to prevent states from “implementing” their own laws authorizing the “use, distribution, possession, or cultivation of medical marijuana.”

Last year, another Justice Department spokesman said it interpreted that provision as blocking prosecutors from “impeding the ability of states to carry out their medical marijuana laws,” but not from charging medical marijuana patients and businesses that violate federal marijuana laws. The measure’s sponsors, Reps. Dana Rohrabacher (R-Calif.) and Sam Farr (D-Calif.) expressed their profound disagreement at the time.

The 9th Circuit is not the first federal court to say the Justice Department got it wrong. Last year a federal judge in an unrelated case ruled that the department can’t prosecute state-legal providers of medical marijuana and said that its interpretation “tortures the plain meaning of the statute.”

Besides the 25 states and D.C. that have already legalized marijuana for medical purposes, voters in nine other states are expected to consider some form of marijuana legalization this year.

Still, the plant remains banned under federal law. States’ efforts to legalize the drug in some form or another have worked only because of guidance from top DOJ officials urging frontline federal prosecutors to refrain from targeting state-legal marijuana operations.

“I applaud the Ninth Circuit Court of Appeals for proclaiming the law as it has been intended by congressional legislation,” Rohrabacher said in an emailed statement to HuffPost. He called the court’s decision a victory for states’ rights, medical marijuana patients and “the constitutional process of establishing law.”

The Justice Department, Rohrabacher said, should “go on notice that there should be no more prosecutions and raiding of dispensaries in those states where the state government has legalized medical marijuana.”

And Farr told HuffPost, “California and many other states allow marijuana to be used for medical purposes yet the federal government still considers it as dangerous as heroin. While I’m pleased to see the amendment that I worked on with my colleagues being interpreted by the courts correctly, there needs to be a permanent change to federal policy to ensure medical marijuana patients aren’t criminalized in states that allow it.”

This story has been updated with comment from Rep. Sam Farr.