The California Supreme Court revived a challenge by psychotherapists Thursday to a state law requiring them to notify the government about any patient who has viewed child pornography.

The law, passed in 2014, expanded statutes from the 1980s that required therapists to report to police or child welfare offices — or face loss of their licenses and criminal prosecution — when a patient has produced, distributed or duplicated images of juveniles engaged in sexual activity. The new law extended the requirement to patients who downloaded or viewed those images.

While viewing child pornography is a crime, under a state law not challenged in Thursday’s case, the therapists argued that mandatory reporting would invade their patients’ privacy and thwart efforts to counsel and treat them.

Lower courts dismissed their suit, saying California’s constitutional right to privacy does not protect either the viewing of child pornography or discussing such illegal conduct with therapists. But a closely divided state Supreme Court reinstated the suit and said the therapists could try to prove the reporting requirement would interfere with the patients’ treatment.

The law affects a “legally protected privacy interest,” the right to make statements during therapy without fear of public disclosure, Justice Goodwin Liu said in the 4-3 decision. Therapists must report communications that reveal threats or dangers to the public, he said, but privacy can still protect “voluntary psychotherapy to treat sexual disorders,” even when the patient admits criminal conduct.

The patients’ revelations “concern the most intimate aspects of human thought and behavior however noxious or depraved,” Liu said. If the therapists can show, for example, that the reporting requirement does little to protect children from sexual abuse, and may even undermine it by preventing treatment, the law must be ruled unconstitutional, he said.

Justices Mariano-Florentino Cuéllar, Leondra Kruger and Joshua Groban joined Liu’s opinion. In dissent, Chief Justice Tani Cantil-Sakauye said the expanded reporting requirement serves a valid purpose and has little or no impact on any legitimate expectation of privacy.

“Children depicted in child pornography are re-victimized every time the content is accessed,” Cantil-Sakauye said, quoting an academic report. She predicted the therapists’ victory would be short-lived, because “the compelling state interest in protecting children from the harm caused by sexual exploitation over the Internet will almost certainly outweigh the alleged privacy invasion” once the case is fully aired.

Lawyers for the therapists were not immediately available for comment. Curtis Cole, who filed arguments on behalf of the state’s major medical organizations — the California Medical Association, California Hospital Association and California Dental Association — applauded the ruling but said the therapists face an “uphill battle” to show that the law interferes with treatment of patients.

Hadar Aviram, a law professor at UC Hastings in San Francisco, likened the case to an Ohio ruling in 2003 that overturned the obscenity conviction of a sex offender for writing fictional accounts of the torture of children in his private journal.

“There is a difference between making a big show of protecting vulnerable children and actually protecting vulnerable children, and both (the Ohio case and the 2014 California law) are examples of the former, not the latter,” Aviram said. “I hope we can bring more facts and less revenge fantasies into our sex offender laws.”

The case is Mathews vs. Becerra, S240156.

Bob Egelko is a San Francisco Chronicle staff writer. Email: begelko@sfchronicle.com Twitter: @BobEgelko