Canadian pop star Justin Bieber pleaded guilty to two lesser charges Wednesday in connection with his January arrest for what police initially alleged was street racing in Miami Beach.

The 20-year-old pop star's plea deal with prosecutors detailed at a Wednesday hearing includes a 12-hour anger management course, a $50,000 charitable contribution and court fines. The deal allows Bieber to avoid a driving under the influence conviction.

Bieber was not present at the hearing before Miami-Dade Circuit Judge William Altfield, who warned the singer to consider the consequences of his actions.

"He has so much to offer and he has so much to lose," Altfield said.

Bieber was arrested early Jan. 23 in Miami Beach after what police described as an illegal street race between Bieber's 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 underage 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, including The Associated Press, that sought access to video of the test and Bieber's lawyers arguing it was an invasion of privacy. Ultimately, Altfield ordered the video released with sensitive portions blacked out. Other police video depicted Bieber walking unsteadily during a sobriety test.

Bieber's legal battles

In July, Bieber resolved another criminal case by pleading no contest to a misdemeanor vandalism charge for throwing eggs at a neighbour's house in Los Angeles. In that case, Bieber agreed to pay more than $80,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.

Bieber shot to stardom at age 15, with his career 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.

With files from CBC News