SAN FRANCISCO – A federal appeals court on Wednesday tussled with the legality of California’s unprecedented ban on gay conversion therapy for minors, suggesting it could be upheld despite concerns for the free speech rights of counselors who support the practice.

During nearly two hours of arguments, a three-judge 9th U.S. Circuit Court of Appeals panel grilled lawyers on both sides of the issue, wondering whether the First Amendment applies to psychotherapy aimed at converting gay teens to being straight. California in January became the first state in the nation to outlaw the therapy, concluding it serves no purpose and is harmful to minors.

(The loopy and absurd technique also became infamous after the 2007 “South Park” episode “Cartman Sucks.” Butters Stotch’s parents thought he was “bi-curious” and sent to him a pray-the-gay-away camp, where several youth committed suicide after being told they were sexually confused. Out in the 562)

Ninth Circuit Chief Judge Alex Kozinski, while clearly concerned about trampling on free speech rights, at one point told a lawyer for parents challenging the law that it seems the Legislature has the leeway to regulate licensed mental health professionals through such a ban.

“It’s really a fine line,” he said. “Why can’t the Legislature say, ‘Look, if you want to be a licensed professional, this is the type of therapy you can’t (do)?’ ”

In two separate cases, a group of therapists and families sued to block the law, arguing it interferes with religious practices and violates therapists’ free speech rights by barring gay conversion discussions between young patients and their counselors. Two Sacramento federal judges have split on the question, one upholding the law and the other finding it violates the First Amendment.

The three-judge panel will decide whether to continue the injunction or to let the law take effect. Lawyers involved in the case said that whichever way this decision goes, appeals are likely to take the case back to a lower court for a full trial and that final resolution in the federal courts could take years.

The case is being closely watched as other states, New Jersey and Massachusetts among them, consider similar laws.

The key question is whether counseling minors to change their sexual preference is medical treatment that can be regulated by the state, or speech that deserves broad First Amendment protections. Ninth Circuit Judge Morgan Christen, an appointee of President Barack Obama, called the issue “pivotal.”

Mathew Staver, head of Liberty Counsel, a group challenging the law, called the California ban “breathtakingly broad,” insisting there is conflicting evidence on whether it is justified and that it is preventing teens who choose the therapy from getting professional help. Therapists who violate the law risk losing their licenses.

But the judges expressed doubts about whether such “talk therapy” is covered by First Amendment protections. Judge Susan Graber asked whether in fact it’s speech or medical treatment. And Christen at another point appeared taken aback when another attorney for the therapists could not offer specific evidence that such therapy succeeds in changing gay minors’ sexual orientation.

The judges, however, also pressed Alexandra Gordon, deputy attorney general, on whether the evidence the Legislature relied upon to enact the ban was too anecdotal to risk eroding free speech protections, citing past court decisions that could be problematic for the state. That includes a recent U.S. Supreme Court ruling striking down California’s ban on the sale of violent video games to minors because it violated the First Amendment.

Kozinski, in fact, noted that psychotherapy generally involves “speaking opinion,” and he expressed concern about the lack of scientific proof of conversion therapy’s harm to minors. “The evidence before the Legislature is weak,” Kozinski told Gordon.

The state’s lawyer disagreed, saying every major medical and mental health organization disapproves of the therapy for minors. Supporters of the ban say the state has a right to regulate licensed professionals and practices considered harmful to minors.

“We’re shutting it down because of the harm of that practice,” Gordon said. “It falls below the standard of care.”