SACRAMENTO — A judge ruled Friday that California regulators violated some farmers’ rights by telling them to stop diverting from rivers and streams, but the state said it can still punish those who illegally take water during the drought.

The temporary restraining order by Judge Shelleyanne Chang of Sacramento Superior Court blocked the state from punishing farmers who ignored a state notice issued earlier this year to stop diverting water. The ruling applies to dozens of farmers in the Central Valley and the irrigation districts serving them.

The two sides had divergent views of what the ruling meant, with lawyers for the farmers suggesting it threw all the state’s cutbacks into question, while the state said it only meant it needed to tweak its notices.

Residents, farmers and businesses across California have endured water restrictions because of the state’s four-year dry spell. Thousands have received so-called curtailment notices in the last year, but only about a third responded to confirm they stopped taking water. The judge ruled Friday that the water board’s notices improperly told districts and landowners with water rights to stop taking water without holding a hearing first.