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.
After Brown 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.
Rihanna 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.
Brown's lawyer, Mark Geragos, said the plea deal includes five years of supervised probation and six months of community labor. Brown will be formally sentenced on Aug. 5.
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."
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.
Copyright 2009 Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.