The parents of the 12-year-old wanted him transferred from the Royal London Hospital in Whitechapel, east London, to a hospice which had agreed to take him.
However Mrs Justice Theis ruled on Friday that Archie should stay under the case of the hospital while life support is withdrawn, so that he can “die in peaceful circumstances”.
A High Court legal hearing on Thursday heard argument from Archie’s parents, who had pledged to “fight to the end” with a last-minute bid to have him transferred to die in a hospice “with dignity”.
The judge gave a delay to treatment being withdrawn until 2pm BST Friday for the family to make an application for permission to appeal directly to the Court of Appeal.
The Court of Appeal confirmed it had received an application for permission to appeal the latest decision.
Doctors treating the schoolboy for the last four months declared Archie to be “brain-stem dead”, prompting a lengthy but ultimately failed legal battle by his family to continue his life support treatment in the hope he would recover.
The child has been in a coma since he was found unconscious at his home in Southend, Essex, on April 7 and is being kept alive by a combination of medical interventions, including ventilation and drug treatments.
His mother, Hollie 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 she wanted her son to “spend his last moments” together with family privately, complaining of a lack of privacy at the hospital.
But in her ruling on Friday morning, Mrs Justice Theis highlighted the risks that Archie would die in transit to the hospice, as set out by a medical professional referred to as Dr F.
“Archie’s best interests must remain at the core of any conclusions reached by this court”, she said.
“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 as outlined by Dr F and the increasing fragility of his medical condition I am satisfied that when looking at the balancing exercise again his best interests remain...that he should remain at the hospital when treatment is withdrawn.”
The judge insisted “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”.
And she paid tribute to Archie’s loved ones, concluding: “Their unconditional love and dedication to Archie is a golden thread that runs through this case.
“I hope now Archie can be afforded the opportunity for him to die in peaceful circumstances, with the family who meant so much to him as he clearly does to them.”
Barts Health NHS Trust argued 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.
The judge also ruled on the family’s bid to continue to give Archie oxygen once life support is withdrawn, saying: “I am satisfied that issue should be left to the clinical team on the ground. Sadly, the evidence points to it being unlikely he will breathe once treatment is withdrawn due his severely compromised medical position and the extent of his injuries.”