The parents of 21-months-old Alfie Evans wanted to take their son to Rome for treatment which they hoped would prolong his life.
But specialists at Alder Hey Children's Hospital argued that continuing to provide treatment was "unkind, unfair and inhumane".
Mr Justice Hayden, who visited Alfie in hospital ahead of his decision on Tuesday, ruled in favour of the hospital and granted it permission to withdraw treatment for the toddler.
He had heard that Alfie, who was born on May 9 2016, was in a "semi-vegetative state" and had a degenerative neurological condition doctors had not been definitively diagnosed.
Alfie's parents, Kate James and Tom Evans, who are both in their 20s, had argued that their son was responding to treatment. Doctors disputed this.
The judge praised Mr Evans and Ms James, saying they had left no stone unturned in their quest for help for their son.
Alfie's mother left the court hearing before Mr Justice Hayden reached his conclusion and, when the decision was announced, Mr Evans broke down.
Mr Justice Hayden said he accepted medical evidence which showed further treatment was futile, adding that he had reached his conclusion with great sadness.
"Alfie's need now is for good quality palliative care.
"He requires peace, quiet and privacy in order that he may conclude his life ad he has lived it, with dignity," he said.
Outside Alder Hey around 30 members of "Alfie's Army" were supporting the family's campaign as they awaited the decision.
Blue and purple balloons fluttered in the wind as they chanted, "Save Alfie Evans!"