SAN FRANCISCO (CN) — A federal judge Wednesday ordered the federal government to redirect water earmarked for commercial interests to help stop a salmon die-off on the California-Oregon border.

The injunction by U.S. District Judge William Orrick III requires the U.S. Bureau of Reclamation to divert water, some allocated for irrigation for farms and ranches, to flush out parasite-hosting worms that cause deadly infections in threatened, juvenile salmon.

Two Native American tribes sued the Bureau of Reclamation last year, claiming its bungled management of Klamath River waterways allowed a deadly parasite called C. shasta to infect 91 percent of juvenile Coho salmon.

The Yurok and Hoopa Valley Tribes say they depend on the salmon for subsistence, income and for traditional ceremonies that define their people.

“I think they’re quite hopeful that this order will reduce the disease rates and let the salmon hold on and maybe begin to recover with dam removal,” the Yuroks’ attorney Patti Goldman said, referring to the federal government’s plan to start tearing down four Klamath River dams by 2020.

Federal officials, irrigation districts and local farmers and ranchers opposed the tribes’ request for an injunction.

But Orrick found the Bureau should have reviewed the project two years ago when infection rates climbed to 81 percent in 2014, then to 91 percent in 2015, well beyond the maximum 49 percent estimated in a 2013 biological opinion issued by co-defendant National Marine Fisheries Service.

“Plaintiffs have presented compelling evidence that the Coho salmon are in a precarious state following years of high C. shasta rates and that the Bureau is unlikely to put protective flows into place absent an injunction,” Orrick wrote in his 53-page ruling.

Scott White, executive director of the Klamath Water Users Association, a trade group representing farmers and ranchers, said it would be “extremely unfortunate” if the injunction resulted in a shortage of water for farmers and ranchers in a higher rainfall year.

“In an above-average water year, to potentially see that impact is a tragedy to our community and to the overall story,” White said.

Local agriculture injects $300 million into the local economy, White said, adding that he feels farmers and ranchers were “kept at arm’s length” while the science was being developed to support the actions ordered in the injunction.

Orrick said he considered the potential impact on communities but concluded that economic interests cannot outweigh potential harm to an endangered species or tribal fishing rights.

“The intervenor defendants undeniably have genuine and important interests, and the court recognizes that the proposed measures might cause hardship to the farmers, ranchers, and their communities,” Orrick wrote. “However, as plaintiffs point out, courts are not permitted to favor economic interests over potential harm to endangered species.”

The irrigation districts, farmers and ranchers also argued that diverting water to help salmon could lower water level in the Upper Klamath Lake, which would threaten another endangered species – the sucker fish.

But the tribes said an injunction would not affect the Bureau’s mandate to maintain minimum lake levels for sucker fish, as required by the Fisheries Service’s 2013 biological opinion.

After a hearing on Jan. 27, Orrick ordered technical experts for both parties to start drafting a plan for flush flows that would save endangered salmon and protect threatened sucker fish. The experts will come up with a temporary plan for flush flows until a new biological opinion is issued and a new management plan in place, Orrick said.

He cited Ninth Circuit rulings that repeatedly held that when an agency exceeds a “trigger,” such as infection rates that surpass the predictions of a 2013 biological opinion, federal agencies must review the project’s impact on an endangered species through formal consultation.

The Bureau argued that the tribes’ request to compel consultation was moot because the government already started that process, though it is still determining the scope for formal consultation, which should take about six months once it officially commences.

Orrick agreed with tribes’ claim that until the National Marine Fisheries Service provides concrete recommendations to the Bureau, a court order to compel such action is appropriate.

The judge ruled that until the formal consultation process has been completed, the Bureau must divert its water for winter-spring flushing flows to flush out parasite-hosting worms. He also ordered the Bureau to release emergency dilution flows from April to June 15 if C. shasta infection rates exceed 30 percent or another rate determined by experts.

Orrick assigned a deadline of March 9 for technical experts to submit a plan for winter-spring flush flows and emergency dilution flows.

Bureau of Reclamation spokesman Louis Moore said the Bureau is reviewing the judge’s ruling and will comply with the legal requirements.

Moore declined to comment on why the Bureau did not take actions earlier when infection rates for endangered juvenile salmon climbed to 81 percent in 2014 and 91 percent in 2015.