The parents of Alfie Evans have lost a last-ditch legal appeal to fly their son to Vatican City in what a high court judge called “the final chapter in the case of this extraordinary little boy”.

A barrister for Tom Evans and Kate James asked Mr Justice Hayden to show “common humanity and common sense” and allow the seriously ill 23-month-old boy to leave Alder Hey hospital in Liverpool.

The judge said all medical experts agreed that further treatment was futile and it would be against Alfie’s best interests to fly to the Vatican’s Bambino Gesù hospital in Rome. However, he added, there was a small possibility Alfie could be cared for at home or in a hospice “for his final days or hours”.

The emergency high court hearing took place amid tight security in Manchester’s civil justice centre on Tuesday evening, hours after Alfie’s life support was withdrawn.

At the end of a highly charged three-hour hearing, the judge ordered Alfie’s parents to engage with doctors and create a palliative care plan that could involve moving him off the paediatric intensive care unit where he has spent the past 16 months of his life.

Hayden said there was no substance to the application by the barrister Paul Diamond that the boy’s condition was “significantly better” than the court or doctors had previously realised. Instead, the judge said Alfie’s continued life was a “shaft of light” and a “special opportunity” for his parents to spend time with him – not the time for more legal manoeuvres.

Though it “may be a forlorn hope”, he added, discussions between the family and doctors may result in Alfie “being cared for, for his final days or hours, at home, or in a hospice or even on a ward, and not on the paediatric intensive care unit”.

The family’s hopes of Alfie being treated in Rome were raised last week when Evans, 21, met the Pope, who expressed support for the couple. Diamond, the family’s barrister, said the case had reached “the highest levels of the Italian government” and that the Italian ambassador’s chief of staff was in court for the hearing. An Italian military air ambulance was on standby if the parents won the appeal, he added.

A spokesman for the Christian Legal Centre, the group bringing court action on behalf of Alfie’s parents, said the boy was able to breathe unaided for six hours after his ventilation was withdrawn at 9.20pm on Monday. However, the court heard that Alfie was then provided with hydration and ventilation at 4am when he became distressed and struggled to breathe.

Hayden said Alfie was “a fighter, resilient, courageous and a warrior” and that “in the last 24 hours, he has proved himself once again to be worthy of all those descriptions”. However, he said, Alfie’s undiagnosed degenerative condition had “almost entirely wiped out” his brain matter, which was now little more than water and cerebrospinal fluid.

The judge was fiercely critical of some of those close to Alfie’s parents. He described Pavel Stroilov, a Christian Legal Centre lawyer who has advised the family, as a “deluded and fanatical young man” who risked imprisonment for contempt of court with some of his legal advice. The court heard that Stroilov had advised Evans to pursue a private prosecution for murder against Alder Hey doctors.

An Alder Hey clinician told the hearing it was currently “impossible” to move Alfie home for palliative care treatment because of the breakdown in the relationship between doctors and the family, and the hostility of some of the boy’s supporters, who have been protesting outside the hospital for days. On Monday a group of them tried to storm the hospital.

The clinician, who cannot be named but who was one of the team treating Alfie on Monday night, said the hostile atmosphere had created a “genuine fear” among fellow doctors and that there would have to be “a sea change” in their relationship with the family before they could consider letting him go home.