Spears, who according to police appeared to be "under the influence of an unknown substance," was strapped to a gurney and rushed to Cedars-Sinai Medical Center. Federline later showed up and custody of the children, Preston, 2, and Jayden, 1, was transferred to him.
A source tells PEOPLE the pop star's court-appointed child monitor called police. "She had already put Preston in the car when Britney locked herself in a room with Jayden," says the source.
Spears, who has visitation rights with the kids, was scheduled to give the boys over to Federline at 7 p.m. Thursday. A bodyguard for Federline arrived to pick up the boys at the designated time, but Spears refused to relinquish her sons, according to a source.
According to police, officers responded around 8 p.m. to a call "about a custodial dispute regarding Britney Spears's children," says Los Angeles police Officer Jason Lee.
Nearly three hours later, police determined that a court order stated that the singer's children, who were with Spears at the time, were supposed to be with Kevin Federline, and a transfer was arranged, according to Lee.
"While officers were on the scene, they observed Ms. Spears under the influence of an unknown substance," Lee added. (PHOTOS: Britney in the ambulance.)
In addition to multiple officers, fire trucks, two ambulances and a police helicopter were all on the scene. Spears was seen being taken to an ambulance on a gurney. (See video here.)
Britney's Father Arrives at HospitalAfter Spears arrived at the hospital, her father, Jamie, and her ex, Federline were spotted there.
Police – as well as Federline's lawyer Mark Vincent Kaplan – arrived at the house close to 8 p.m., though Kaplan was later seen leaving.
Earlier in the day, Spears showed up 90 minutes late to a scheduled deposition in her custody case – and stayed for only a fraction of an hour.
Back at her Studio City home directly after the hearing, when a photographer asked if Kaplan was nice to her, Spears, 26, responded with an emphatic, "No!"
When reached by PEOPLE, Spears's lawyer Sorrell Trope, who on Wednesday filed a request to withdraw from the singer's custody case, said only: "No comment."
PHOTOS: See the latest pics from Britney Spears's troubled life.
Reporting by PERNILLA CEDENHEIM, JENNIFER GARCIA, MARISA LAUDADIO and KEN LEE