Superior Court Judge Scott M. Gordon ruled Monday that Britney Spears' ex-husband Kevin Federline will take Sean Preston, 2, and Jayden James, 1, beginning Wednesday "until further order of the court."
Click here to see photos
The order stemmed from an unspecified oral motion made by Federline's lawyers and was handled in a closed-door hearing. The judge's order did not state the reason for the change in custody and he ordered all transcripts of the proceedings sealed.
Phone messages left for representatives of Spears and Federline were not immediately returned Monday.
Last month, Gordon said Spears engaged in "habitual, frequent and continuous use of controlled substances and alcohol" and ordered her to undergo random drug and alcohol testing twice a week as part of her ongoing custody dispute with Federline.
Spears also was previously ordered to meet weekly with a "parenting coach" who was to observe and report back to the court about her parenting skills. Both Spears and Federline must complete the court's "Parenting Without Conflict" class.
Spears, 25, and Federline, 29, were married in October 2004. She filed for divorce last November and it became official in July. The two have joint custody of their sons, but Federline is seeking a greater share of custody.
Since Spears became single, her troubles have played out in the tabloids. First she was photographed at various Hollywood hotspots partying hard with Paris Hilton - appearing drunk and out-of-control. Some photos captured the pop star without panties. Then Spears shaved her head as paparazzi captured the moment, beat a car with an umbrella and ended up spending a month in rehab.
An MTV Video Music Awards performance last month meant to herald her comeback was universally panned, with Spears appearing spaced-out and lethargic - and, in some eyes, less than buff. The following week, Spears' management firm dropped her and her divorce lawyer resigned.
She then was charged with misdemeanor counts of hit-and-run and driving without a valid license for allegedly crashing into a parked car in August.
The driving offenses likely compelled the judge to issue Monday's orders, said New York divorce lawyer Raoul Felder.
"She was driving without a license with a child in the car," he said. "You can put aside the in and out of rehab, the shaving her head. But this? When a judge went out on a limb for her? There's no going back."
Though Spears must relinquish physical custody of the children until further ruling from the court, she and Federline still share legal custody.
Los Angeles divorce lawyer Connolly Oyler said he's surprised the children weren't taken from Spears sooner. Judges typically remove youngsters from households where parents are ordered to undergo drug testing, he said.
"There may have been another incident and the judge had had enough," Oyler said.
But, he added, all is not lost for Spears.
"If she picks a good counselor and gets a different set of friends, there's a good chance she can turn things around," he said, noting "she's only 25."
The couple is due back in court Oct. 3. Spears' new album is set to be released Nov. 13.