SAN FRANCISCO – A federal appeals court sided with California on Thursday and upheld the first law in the nation banning a psychological treatment that seeks to turn gay youths straight.

In a unanimous opinion, a three-judge panel of the 9th U.S. Circuit Court of Appeals found the state law barring the so-called gay aversion therapy legal in every respect.

The judges said trying to change a minor’s sexual orientation through intense therapy appeared dangerous, and that California lawmakers properly showed that the sexual orientation change efforts were outside the scientific mainstream and have been rejected for good reason.

“One could argue that children under the age of 18 are especially vulnerable with respect to sexual identity and that their parents’ judgment may be clouded by this emotionally charged issue as well,” Judge Susan Graber wrote for the court panel.

The California Legislature cited reports, experts and anecdotes involving suicides, substance abuse and other behavior by young recipients of the therapy before members voted last year to ban it for minors.

“Efforts to change a young person’s sexual orientation pose critical health risks, including depression, shame, decreased self-esteem, social withdrawal, substance abuse, self-harm and suicide,” Lambda Legal, which defends gay rights, said in an email statement about Thursday’s ruling.

The activities of pastors and lay counselors who are unlicensed but provide such therapy through church programs are not covered by the law.

New Jersey Gov. Chris Christie has signed a law that would outlaw the therapy in his state.