Archie Battersbee's parents have lost a High Court bid to have him transferred to a hospice before his life-sustaining treatment is withdrawn.
The 12-year-old has been in a coma since he was found unconscious by his mother in April and is currently being kept alive by a combination of medical interventions, including ventilation and drug treatments, at the Royal London Hospital in Whitechapel, east London.
His parents have fought a long-running legal battle over the withdrawal of his treatment, which ultimately failed on Wednesday when the European Court of Human Rights refused to intervene.
His mother Hollie Dance, and father Paul Battersbee, launched an urgent bid to have him transferred to a hospice to die, resulting in a hearing which ran until late on Thursday night.
But, in a ruling on Friday morning, Mrs Justice Theis concluded it was not in Archie's best interests to be moved.
The judge said: "Archie's best interests must remain at the core of any conclusions reached by this court.
"When considering the wishes of the family, why those wishes are held, the facilities at the hospice, what Archie is likely to have wanted, ... the risks involved in a transfer ... and the increasing fragility of his medical condition, I am satisfied that when looking at the balancing exercise again his best interests remain as set out (in the ruling of July 15), that he should remain at the hospital when treatment is withdrawn.
"The circumstances outlined by Dr F of the physical arrangements at the hospital and the arrangements that can be made will ensure that Archie's best interest will remain the focus of the final arrangements to enable him peacefully and privately to die in the embrace of the family he loved.
"The parents in the email from their solicitors on August 2 confirmed, in principle, their willingness to co-operate in these arrangements."
The child has been in a coma since he was found unconscious at his home in Southend, Essex, on April 7.
Ms Dance believes he was taking part in an online challenge at the time he became ill. He has not regained consciousness since.
Ms Dance said on Thursday that she wanted her son to "spend his last moments" together with family privately, complaining of a lack of privacy at the hospital.
She told Times Radio on Thursday: "We can't even have the chance to be in a room together as a family without nurses."
She added: "There's absolutely no privacy, which is why, again, the courts keep going on about this dignified death - why aren't we allowed to take our child to a hospice and spend his last moments, his last days together privately?
"Why is the hospital obstructing it?"
Barts Health NHS Trust has said Archie's condition is too unstable for a transfer and that moving him by ambulance to a different setting "would most likely hasten the premature deterioration the family wish to avoid, even with full intensive care equipment and staff on the journey".
A High Court order made in July requires that Archie remains at the Royal London Hospital while his treatment is withdrawn.
A family spokeswoman said a hospice has agreed to take him.