The deputy district attorney wanted the 24-year-old actress -- who violated probation in her DUI case because she failed a drug test -- behind bars for 180 days, but her attorney argued that she should remain in rehab at the Betty Ford Center in Rancho Mirage, Calif.

When the judge ordered her back to rehab, Lohan began to cry and said thank you.

VIDEO: How Lindsay wound up in jail, rehab, and jail again

Judge Fox told her after Jan 3, 2011, she would be randomly tested for drugs and alcohol. He also stressed that she must continue to work with her doctor and counselors.

The judge told her she also must not have any positive tests until the next hearing date of Feb. 25, 2011, or she would return to the slammer.

PHOTOS: Child stars gone bad

He then said, "If you can make it, I will convert you to unsupervised probation and you will be able to move on with your life, put the episode, this long episode behind you."

When the hearing was over, the actress turned around hugged her attorney and said, "Oh, my god."