(CNN) - Justin Bieber made a $50,000 donation to a youth charity as part of a plea deal to settle a Miami drunken driving case Wednesday.
Bieber, 20, was not in court when a judge accepted his guilty plea to careless driving and resisting arrest in connection with the Miami Beach incident last January.
Prosecutors dropped the drunken driving charge in the agreement, which requires Bieber to get 12 hours of anger management counseling, attend a program that teaches about the impact of drunken driving on victims and make the large donation to the "Our Kids" organization.
The charity donation, although a prosecution demand, could not legally be required in the plea deal, a prosecutor noted during the hearing. As a result, the payment was made before the judge accepted the agreement.
Judge William Altfield delivered a lecture to Bieber, which he hoped his lawyers would relay to their client, asking him to become a better role model for his young fans.
"I hope that he realizes that his actions not only lead to consequences that affect him, but they lead to consequences that affect others who are looking up to him as a role model," the judge said.
Although Bieber has never been charged with a felony crime or a drug charge -- and he has never been in drug or alcohol rehab -- the judge compared the singer to actor Robert Downey Jr. when he was young.
Altfield said that Downey got into trouble "because of the drugs, because of the alcohol, because of the fame, because of all of the pressures that he had on a daily basis and look at what he's done with his life. He turned himself around."
"Here is someone who is young," Altfield said of Bieber. "His whole life is ahead of him and he just hopefully will get the message. He will grow up. He will use all of his talents positively for young persons."
The lead prosecutor, in a written statement to CNN, said "the strengths and weaknesses of the case" led both sides to agree to the plea deal.
"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," State Attorney Katherine Fernandez Rundle said. "The intervention and counseling parts of the plea should provide a pathway toward adult responsibility."
Miami Beach Police Chief Raymond Martinez said officers arrested Bieber January 23 after they saw him driving a yellow Lamborghini in a race against a red Ferrari in a residential area. The cars were speeding at about 55 to 60 mph in a 30 mph zone, he said.
Police said Bieber was argumentative during the arrest and failed a field sobriety test.
Bieber has had a number of run-ins with the law in recent months.
In July, a judge in Los Angeles ordered Bieber to pay $80,900 restitution for damaging his former neighbor's mansion by throwing eggs.
The pop star accepted a plea deal to settle a vandalism charge that puts him on probation for two years. The probation will be supervised until he completes 12 weekly anger management sessions, works five days of community labor and pays the restitution.
He was charged with assault in January after he was accused of hitting his limousine driver in Toronto.
In January, the Federal Aviation Administration looked into allegations that Bieber and other passengers on board a charter flight from Canada to New Jersey interfered with the flight crew, the agency said. In July, the FAA cleared them.
In February, police in Georgia searched Bieber's limousine and found small amounts of marijuana and drug paraphernalia. No charges were filed "due to the small amount," police said.