Britney Spears' former husband Kevin Federline has been given sole custody of the couple's two young sons.
Spears has been embroiled in a battle over her sons since 2006
The pop star was also told by a court in Los Angeles she had lost the right to visit Sean Preston and Jayden James.
Spears has reportedly now left the hospital she was taken to after being stretchered out of her hilltop mansion.
She was involved in a three-hour stand-off with police, who were called when Spears refused to return the children after a monitored visit.
Another custody hearing has been set for 14 January.
"I'm not happy about any of these events," said Federline's lawyer, Mark Kaplan, after the hearing. "There's no winners here."
Federline had previously been awarded temporary custody of Sean Preston, who is two years old, and Jayden James, who is one.
But Spears was still allowed to see her children for one day each week at that stage.
The nature of the 26-year-old's medical problems have not been revealed.
Dr Phil McGraw, a television therapist who visited the pop star, says she has been released but that she was "in dire need of both medical and psychological intervention".
Police were called to Spears' home at 2000 on Thursday (0400 Friday GMT) over a family custodial argument that they tried to resolve "peacefully by court order", police officer Jason Lee said.
After nearly three hours, Spears reportedly handed over her children and was taken away on a stretcher.
There were dramatic scenes, our correspondent adds, with paparazzi photographers chasing the ambulance carrying the star.
It is reported that police found the singer under the influence of an unknown substance, and she was taken to hospital for medical evaluation.
Spears was not arrested, and "there was no actual crime", a police spokeswoman said.
The singer's lawyers filed a court motion earlier this week asking to be relieved as her representatives owing to a "breakdown" in communication.
Spears and Federline were married in September 2004 and divorced in July 2007.