Mr Justice Hayden said specialists could lawfully move the eight-week-old boy, who has a severe liver impairment, to a palliative care regime.
The judge ruled that the identity of the baby must not be given, and the name of the hospital must be withheld to protect his identity.
The boy's parents praised the efforts doctors and nurses had made but thought all options had not been exhausted.
They also said stopping life-support treatment was against their Muslim beliefs, and argued that while there was breath there was life, and while there was life there was hope.
But specialists told the judge that there was no prospect of the boy, who had been in intensive care since he was three days old, surviving.
Doctors said he had been diagnosed with necrotising enterocolitis, a condition, commonly known as NEC, which causes tissues in the intestine to become inflamed and start to die.
They said he could not breathe without the aid of a ventilator and would die in pain if allowed to die naturally.
Mr Justice Hayden, who is based at the Royal Courts of Justice in London, said ending intensive care was in the boy's best interests.
He made a ruling late on Tuesday after considering the case at a virtual hearing in the Family Division of the High Court.
Bosses at Sheffield Teaching Hospitals NHS Foundation Trust have responsibility for the baby's care and had asked the judge to decide what moves were in his best interests.
They said they had hoped that an agreement could be reached with the boy's parents without the need for a court hearing.
The judge considered evidence at a private hearing.
The baby's parents, who were not represented by lawyers, watched proceedings on a mobile phone from hospital while sitting near their son.
His father addressed the judge and argued that life-support treatment should continue.
Covid-19 restrictions meant that he had not been able to visit hospital when his son was born, he said.
He said he had only seen his son in intensive care.
At one point the judge asked lawyers, and a reporter, to log out of the virtual hearing so he could look at the baby, via the father's mobile, with the parents.
Mr Justice Hayden said the baby's parents held "profound" Islamic beliefs. He said the father believed while there is life there is hope.
"However, the clinical team are satisfied that there is no prospect of (the boy) surviving.
"The challenge is to ensure that his death is as comfortable and as dignified and as free from pain as can practically be achieved."
He added: "I believe it is in the best interests of (the boy) to stop intensive care to move to palliative care.
"I am satisfied that intensive care is futile."
Mr Justice Hayden told the baby's parents: "I am so sorry."