A judge temporarily stripped Charlie Sheen of custody of his twin sons Tuesday, after Brooke Mueller submitted a declaration in which she alleged Charlie said, "I will cut your head off, put it in a box and send it to your mom" ... TMZ has learned.
TMZ broke the story ... Brooke's lawyer got a temporary restraining order against Charlie, prohibiting him from going near her. The judge also ordered Charlie to surrender their twin boys -- Bob and Max -- to Brooke while the TRO remains in effect.
Police removed the twins from Charlie's house late Tuesday.
According to legal docs, Brooke also claims ... on February 23 Charlie threw a phone inside his house and then with a penknife in hand, threatened to stick it in Brooke's eye.
Today's hearing was held without notice to Charlie -- his lawyers were not present.
Brooke's lawyer confessed to the court ... Brooke is currently in a "day treatment" facility for substance abuse. She says she will see the kids for around 4 hours a day while the TRO is in effect and her mom will provide care for the rest of the day.
Sources tell TMZ Charlie's team is furious that the order was issued and plans to go to court tomorrow in an attempt to undo it.
Charlie tweeted Tuesday night, "My sons are fine ... My path is now clear ... Defeat is not an option!"
UPDATE: Charlie was just live on "Today" where he said he didn't say those words, adding "it's colorful ... that's a good one I guess. If you spend enough time around me you can formulate things and make it sound like it could have come from my mouth, but you can do that watching reruns."
He also looked at the camera and sent out a message directly to Brooke, saying "I'm sorry you felt this had to be done in this way, but this does not display any responsible parenting."