WASHINGTON — The Supreme Court on Wednesday upheld a Tennessee law that prohibits some medical treatments for transgender youths, rejecting arguments that it violated the Constitution and shielding similar laws in more than 20 other states.

The decision, which came amid the Trump administration’s fierce assaults on transgender rights, was a bitter setback for their proponents, who only five years ago celebrated a decision by the court to protect transgender people from workplace discrimination.

The vote was 6-3, with the court’s three liberal members in dissent. Chief Justice John Roberts, writing for the majority, acknowledged the “fierce scientific and policy debates about the safety, efficacy and propriety of medical treatments in an evolving field. The voices in these debates raise sincere concerns; the implications for all are profound.”

But he said these questions should be resolved by “the people, their elected representatives and the democratic process.”

The Tennessee law, enacted in 2023, prohibits medical providers from prescribing puberty-delaying medication, offering hormone therapy or performing surgery to treat gender dysphoria, the psychological distress caused by incongruence between experienced gender and that assigned at birth. It was part of a sweeping national pushback to expanding rights for transgender people. Since then, debates about military service, athletics, bathrooms and pronouns have played a role in President Donald Trump’s second-term agenda.

In dissent, Justice Sonia Sotomayor wrote that Wednesday’s decision could have tragic consequences.

“If left untreated, gender dysphoria can lead to severe anxiety, depression, eating disorders, substance abuse, self-harm and suicidality,” she wrote in an opinion joined by Justices Elena Kagan and Ketanji Brown Jackson.

In a measure of the shifting politics around transgender issues, the Biden administration had argued against the Tennessee law. After Trump returned to office, he issued an executive order directing agencies to take steps to curtail surgeries, hormone therapy and other gender transition care for youths under 19. And in February, his administration formally reversed the government’s position in the case and urged the justices to uphold the law.

The doctor and three families who sued to challenge the Tennessee law said it discriminated based on both sex and transgender status in violation of the Constitution’s equal protection clause, which requires states to have a valid reason for treating similarly situated people differently. They noted that the law specified that the prohibited treatments were allowed when undertaken for reasons other than gender transition care.