Chris Brown has pleaded guilty to one count of felony assault on pop star Rihanna.
Brown entered his plea before a preliminary hearing was scheduled to start in Los Angeles on Monday.
Rihanna had been on standby to testify.
PHOTOS: Click here to see photos of Rihanna.
Brown will be sentenced on Aug. 5, but the terms of the plea deal call for him to serve five years of formal probation and six months — roughly 1,400 hours — of community labor. Brown will be able to complete his probation in his home state of Virginia; he will have to do either graffiti removal or roadside cleanup for his service.
A spokeswoman for the Los Angeles County district attorney's office said the terms were in line with what others receive when they're charged with similar crimes and who have no prior criminal history.
Los Angeles Superior Court Judge Patricia Schnegg also ordered the singer to stay away from Rihanna.
After Brown entered his plea and left the courtroom, Rihanna entered and was addressed by Los Angeles Superior Court Judge Patricia Schnegg, who explained to the Barbados-born singer that she had issued a stay-away order.
PHOTOS: Click here to see photos of Chris Brown.
Rihanna, 21, had not been seeking a stay-away order, but the judge imposed one. The order requires that Brown and Rihanna stay at least 50 yards from each, except at industry events when the distance is reduced to 10 yards.
The judge also told Rihanna it's not a one-way order and she will be in violation if she gets closer to Brown than the order allows.
Rihanna was informed of the deal about an hour she could have been called as a witness, her attorney, Donald Etra, said. He said the singer "did not object" to the terms of the deal.
Schnegg accepted Brown's plea, but expressed some concerns because Brown is not a California resident. She said Brown likely will be allowed to do his community service in his home state of Virginia. He'll have to return to California for updates every three months. He'll also be required to attend domestic violence classes.
Brown spoke softly throughout the hearing as he waived his rights and told the judge he understood the gravity of his plea.
"I think it's commendable you took responsibility for your conduct," Schnegg told Brown.
She said she hoped "the terms and conditions of your probation will have some meaning."
PHOTOS: Click here to see celebrity tragi-couples.
The deal provides an end to a case that sparked intense media interest and severe backlash against Brown. Sponsors and radio stations dropped him, and the singer had to cancel several high-profile appearances, including a performance at the Grammys.
The singer once known for his squeaky-clean image now has a substantial blemish on his record. He must now also remain out of trouble for the foreseeable future.
Lawyers for Brown and Rihanna have refused to discuss the status of the pair's relationship.
Brown was arrested Feb. 8, hours after police say he hit and threatened Rihanna after leaving a pre-Grammy party in Los Angeles. He was later charged with felony assault likely to produce great bodily harm and making criminal threats.
If convicted, the singer faced sentences ranging up to nearly five years in prison.
Brown, 20, rose to fame after the 2005 hit "Run It!" and his popularity has only grown. He was nominated for a Grammy for "No Air" with Jordin Sparks and named Billboard's top artist in 2008.
In the months since the incident, both musicians have gradually appeared in public more frequently. Lately they have been photographed separately, including at a National Basketball Association finals game between the Orlando Magic and Los Angeles Lakers.
Rihanna, 21, recorded one of 2007's most popular songs with "Umbrella" and has numerous other hits. Her looks have made her a cover girl for magazines, as well as a pitchwoman for Cover Girl cosmetics.