Justice Nicholas Francis ruled with the "heaviest of hearts" but "complete conviction" that life support treatment in London for eight-month-old Charlie Gard should be ended.
The baby boy suffers from a rare genetic condition and has brain damage, from which he will not recover according to experts consulted by the court.
The judge's ruling was met with a scream of "no!" and Charlie's parents, Connie Yates and Chris Gard, wept as the decision was announced.
Francis had visited baby Charlie in hospital and during the ruling praised the staff there for the "extraordinary care" provided to the child and his family.
More From This Section
"Most importantly of all, I want to thank Charlie's parents for their brave and dignified campaign on his behalf, but more than anything to pay tribute to their absolute dedication to their wonderful boy," he said.
The child's parents had hoped to take him to the US where he would undergo a treatment trial for his form of mitochondrial disease.
The family's lawyer Laura Hobey-Hamsher said they were "devastated" by the court's decision and would consider appealing.