A ban on puberty blockers introduced by the previous government using emergency legislation was lawful, the High Court has ruled.
Former health secretary Victoria Atkins curbed the use of the drugs for children and young people with gender dysphoria under emergency powers at the end of May.
A trans campaign group then took legal action, arguing that she had failed to consult patient groups and misused the emergency process.
Health Secretary Wes Streeting said he welcomed the court ruling, adding that children's healthcare must be "evidence-led".
Campaign group TransActual UK said it condemned the decision by the High Court and would try to appeal.
The case follows the review by Hilary Cass earlier this year which found a lack of evidence around treatment for under-18s with puberty-blocking drugs.
Puberty blockers are drugs used to delay or prevent puberty happening.
In March 2024, NHS England decided that puberty blockers would no longer be routine treatment for children with gender dysphoria. At that point, puberty blockers were only allowed to be used in NHS clinical trials.
In May, following the Cass Review, the Conservative government tightened rules on the drugs, introducing an emergency ban on them being prescribed by private and European prescribers.
Puberty blockers are now only available to under-18s with gender dysphoria who are already taking the drugs. They can also be used in NHS clinical trials and in a few other circumstances.
TransActual challenged the order made by the then health secretary to further restrict the use of puberty blockers.
Following the High Court ruling, Mr Streeting said he welcomed the decision.
"Children's healthcare must be evidence-led," he said. "Dr Cass's review found there was insufficient evidence that puberty blockers are safe and effective for children with gender dysphoria and gender incongruence.
"We must therefore act cautiously and with care when it comes to this vulnerable group of young people."
Mr Streeting said he was working with NHS England to improve children's gender identity services, and was setting up a clinical trial to establish the evidence on puberty blockers.
"I want trans people in our country to feel safe, accepted, and able to live with freedom and dignity," he added.
Chay Brown, director for healthcare at TransActual, said the result of the case was "disappointing".
"Defence evidence makes clear that they decided on an emergency ban first and sought ways to justify it second," he said.
"We are seriously concerned about the safety and welfare of young trans people in the UK."
Mr Brown said trans researchers were excluded from the review team and it was led by someone who has since been elevated to the House of Lords by the outgoing Conservative administration.
The Good Law Project, which is working with TransActual, said future consultations on young people's healthcare "must be taken seriously and include input from real experts and those most directly affected by the changes".
"Young people, whether they are trans or not, should be able to access the medication they need to live full, happy and healthy lives," said Bekah Sparrow, legal manager.