Lindsay Lohan just copped an 11th hour plea deal and will spend 90 days in lockdown rehab ... the good news for her ... she's dodged the jail bullet.
After a lot of haggling in chambers with offers and counteroffers, Lindsay pled no contest to the crimes of reckless driving and lying to cops. In addition to rehab, Lindsay will perform 30 days of community labor and undergo psychotherapy for 18 months -- she'll get credit for shrink time already completed.
FYI -- there's a mandatory 5 days in jail for reckless driving, but it's going to be folded into the lockdown rehab so she won't be behind bars even for a day. Lindsay will be able to do her rehab in NYC. She must stay clear of drugs and drug users. She must submit to drug testing.
She's also admitted to a probation violation in the jewelry heist case, she was sentenced to 180 days in jail, but that sentence was STAYED and she won't do time if she continues to obey all laws.
During the hearing, Lindsay's attorney Mark Heller kept jumping up to talk -- and Lindsay ran out of patience ... telling him, "Don't say anything else." Heller ignored her and got up to talk again, and Lindsay said, "Oh my god, I'm going to kill you." Priceless.
Lindsay showed up 48 minutes late after missing 2 commercial flights from NYC to L.A. She took a private jet and landed a little too late.
The judge also offered a suggestion, "Don't drive."
On her way in, someone threw glitter at Lindsay.
Lindsay Lohan and Mariah Carey -- avoid glitter at all costs.