MIAMI -- Pop singer Justin Bieber pleaded guilty Wednesday to misdemeanour charges of careless driving and resisting arrest seven months after his arrest in Miami Beach following what police initially called an illegal street 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 $50,000 charitable contribution and a $500 fine. The deal allows Bieber to avoid a driving under the influence conviction. A charge of driving with an expired license was dropped when Bieber showed proof he has a valid one.

Bieber was not present at the hearing before Miami-Dade County Judge William Altfield. Defence attorney Mark Shapiro said Bieber had already given the $50,000 to a local children's charity.

Altfield 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 who have watched him get into several recent scrapes with the law.

"I hope that he realizes that his actions not only lead to consequences that affect him but they lead to consequences that affect others that are looking up to him as a role model," Altfield said. "He just hopefully will get the message. He will grow up. He will use his talents positively for young persons."

Another of Bieber's attorneys, Howard Srebnick, said Bieber will be told of the judge's comments.

"We will turn this into a positive experience," Srebnick said. "We're relieved that it's over."

Bieber was arrested early Jan. 23 in Miami Beach after what police described as an illegal street race in an upscale residential neighbourhood 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.

Still, Miami-Dade State Attorney Katherine Fernandez Rundle said Miami Beach officers were right to stop the pair.

"The ultimate purpose of the Miami Beach Police Department's initial traffic stop was to end some rash juvenile type conduct before a tragedy occurred," she said.

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, which 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.

In July, Bieber resolved another criminal case by pleading no contest to a misdemeanour 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.

Back 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 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."