LONDON (AP) — Critically ill baby Charlie Gard will be transferred to a hospice and taken off life support unless his parents and a hospital agree on a plan that could potentially keep the child alive for a bit longer, a British judge ruled Wednesday.

High Court judge Nicholas Francis gave 11-month-old Charlie’s parents and the hospital that has been treating him until noon Thursday to come to terms on an end-of-life care plan for the infant’s final hours or days.

The baby suffers from a rare genetic disease, mitochondrial depletion syndrome, which has caused brain damage and left him unable to breathe unaided. Recent tests found Charlie has irreversible muscular damage.

“It is in Charlie’s best interests to be moved to a hospice and for him at that point to be moved to a palliative care regime only,” the judge said as a medical and legal battle that has drawn international attention nears a wrenching conclusion.

The parents, Connie Yates and Chris Gard, spent months trying to persuade Great Ormond Street Hospital to let Charlie go to the United States for experimental treatment. They gave up their fight on Monday, acknowledging that the window of opportunity to help him had closed.

On Tuesday, they said they hoped to bring their son, whose 1st birthday is next week, home to die. Francis said Charlie’s mother and father now accept that the only options for their son “are the hospital or the hospice.”

The Thursday deadline is meant to yield a plan for what happens after the baby is transferred to a hospice. The parents want him kept on his ventilator for a time. The hospital, in fighting the parents’ earlier effort to secure experimental treatment, had indicated that it was responsible for sparing Charlie unnecessary pain.

Francis said if the parties do not reach an agreement, Charlie will be taken to hospice and the ventilation system keeping him alive will be turned off. He issued an order barring publication of the name of the hospice and the date when Charlie is taken there.

The judge said it was a “very, very sad conclusion.”

Charlie’s mother left the courtroom in distress before the judge gave his ruling.

“What if it was your child?” Yates said amid sobs. As she left, she said: “I hope you are happy with yourselves.”

In conceding that Charlie would leave the hospital for a hospice instead of home, Yates requested a medical team of her choosing that would work to keep her son alive for a week. He is not expected to survive for more than a few hours once his ventilator is removed.

The request indicated that the parents had backed away from their earlier expressed wish to take Charlie home for “a few days of tranquility” before his ventilator was disconnected and he was allowed to “slip away.”

Great Ormond Street Hospital said it was not practical to provide life-support treatment for days at the couple’s home. Nurses from the hospital nonetheless have volunteered to care for him in his final hours.

The parents’ cause caught the attention of U.S. President Donald Trump and Pope Francis and also garnered widespread grassroots support. U.S.-based anti-abortion activists have flown to London to support Charlie’s parents.

The case has become the catalyst for discussions on health care funding, medical intervention, the role of the state and the rights of the child.

The heated commentary has prompted the judge to criticize the effects of social media and those “who know almost nothing about this case but who feel entitled to express opinions.”