Troubled US actress Lindsay Lohan was sentenced Monday to 90 days in a locked rehab facility, as part of a plea deal announced as her trial for allegedly lying to police was set to begin.

The 26-year-old starlet, who rushed into the courtroom nearly one hour behind schedule, was also sentenced to two years' probation after pleading no contest to misdemeanor charges stemming from the car crash in Santa Monica in June 2012.

Lohan will have to carry out 30 days of community labor -- which she can do in New York, where she currently lives -- and undergo 18 months of psychotherapy. The deal also suspends a 180-day jail sentence for a separate probation violation.

"By locked facility, I mean that there are not day passes, you can't leave, you have to stay within the program for the 90 day period until you're done," said Los Angeles Superior Court Judge James Dabney.

"Do you understand and accept all the conditions of the probation in this matter?" Dabney asked.

"Yes, sir," answered Lohan, who was dressed in white and wore no makeup.

The judge told Lohan's lawyers that the actress will also "have to prove she doesn't have any alcohol or drugs in her system and not to use, possess any narcotics ... or restricted drugs or associated paraphernalia."

The current round of trouble is related to the June crash when the Porsche she was driving hit a truck on the Pacific Coast Highway.

Lohan at first claimed she was a passenger in the car, but an investigation later showed that she had been the driver.

After the accident, Lohan was charged with obstructing a police officer, giving false testimony and driving recklessly.

The charges meant that Lohan had violated the terms of probation after she was sentenced for stealing a necklace in 2011, and, if she were found guilty, would have landed her in prison.

"A suggestion: don't drive," Dabney told Lohan. "You're in New York, you don't need to drive. But it's not a condition of the probation."

However, Dabney said, "you really need to understand that ... this is it. You violate your probation and we're not going to be be having discussions about putting you back on probation in either of these cases."

Monday's appearance was the 19th time that Lohan showed up in court in less than five years, according to a tally by specialty magazine On The Red Carpet.

Lohan's lawyer was happy about the outcome.

"I'm very confident you won't be seeing Lindsay Lohan in any criminal court any time in the future," Heller told reporters outside the courthouse.

"She has fully recognized all the issues that have to be addressed, and I'm very confident she will be able to move forward in her life with dignity, with pride, and with respect," he said.

Lohan showed up late because she missed her late Sunday flight from New York to Los Angeles, but later traveled aboard a private jet provided by Mr. Pink Beverages, a company that sells energy drinks, Lohan wrote in a message on Twitter.