Pop singer Justin Bieber has pleaded guilty to charges of careless driving and resisting arrest seven months after he was held in Miami Beach following what police initially called a drag race.
The 20-year-old pop star's plea deal with prosecutors, detailed at a court hearing, includes a 12-hour anger management course, a £30,000 charitable contribution and fines. The deal allows Bieber to avoid a driving under the influence conviction.
He was not present at the hearing before Miami-Dade County Judge William Altfield. Defence lawyer Mark Shapiro said Bieber had already given the money to a local children's charity.
The singer was arrested early on January 23 in Miami Beach after what police described as an illegal street race between his rented Lamborghini and a Ferrari driven by R&B singer Khalil Amir Sharieff.
Neither was charged with drag racing and there was little evidence they were even exceeding posted speed limits.
Alcohol breath tests found Bieber's level below the 0.02 limit for under-age drivers, but urine tests showed the presence of marijuana and the anti-anxiety drug Xanax in his system.
Bieber was also charged with resisting arrest after a profanity-laced tirade against police officers, as well as driving on an expired license.
The urine test itself became a battle between media companies that sought access to video of it and Bieber's lawyers arguing it was an invasion of privacy.
Ultimately, Mr Altfield ordered the video released with sensitive portions blacked out. Other police video depicted Bieber walking unsteadily during a sobriety test.
In July, Bieber resolved another criminal case by pleading no contest to a vandalism charge for throwing eggs at a neighbour's house in Los Angeles. In that case, he agreed to pay more than 80,000 dollars (£48,000) in damages and meet a number of other conditions.
Bieber is also charged in Toronto with assaulting a limousine driver in late December. His lawyers have said he is not guilty in that case.
Also in Miami, Bieber is being sued by a photographer who says he was roughed up while snapping pictures of the singer outside a recording studio.
The Canadian-born singer shot to stardom at age 15. His career was overseen by two music industry heavyweights, singer Usher and manager Scooter Braun, after initially gaining notice through YouTube videos.
He was nominated for two Grammy Awards for his 2010 full-length album debut My World 2.0.
The judge said he wants the case and the worldwide negative publicity it generated for Bieber to serve as an important lesson to the singer and, perhaps more importantly, his millions of fans.
"He just hopefully will get the message. He will grow up. He will use his talents positively for young persons," he said.
Another of the singer's lawyers, Howard Srebnick, said Bieber will be told of the judge's comments.
"We will turn this into a positive experience," he said. "We're relieved that it's over."