R&B singer Chris Brown has pleaded guilty in the US to one count of assault on his former girlfriend, pop star Rihanna.
Brown, 19, was sentenced to five years' probation and ordered to do six months of community service.
Brown had faced charges of assaulting Rihanna, 21, during a row in February.
The last-minute plea deal came before a hearing at a Los Angeles court at which Rihanna was due to give evidence. She said the sentence was "fair".
Brown had been facing a potential jail sentence of four years.
His sentence involves five years of supervised probation and six months of community labour, such as picking up litter or removing graffiti.
He will also have to attend courses on domestic violence.
Rajesh Mirchandani reports from outside the LA court room
Los Angeles Superior Court Judge Patricia Schnegg told him: "I think it's commendable that you took responsibility for your conduct, sir."
Speaking outside the court, Brown's lawyer Mark Geragos said: "He embraces this as a chance to get the message out that domestic violence will not be tolerated. He wants to get his life back on track."
After Brown left the courtroom, Rihanna entered and was addressed by Judge Schnegg who explained to the Barbados-born singer that she had issued a stay-away order.
The singer had not been seeking such an order, but the judge imposed one anyway.
The order requires that Brown and Rihanna stay at least 50 yards (45m) from each other, except at entertainment industry events when the distance is reduced to 10 yards (9m).
The judge also told Rihanna it is not a one-way order - and that she, too, should not get any closer to Brown than the order allows.
Rihanna's lawyer, Donald Etra, said the singer believed it was a "fair and just resolution" to the case.
Rihanna was due to give evidence in court
Brown will be formally sentenced on 5 August.
Brown, whose hits include With You and No Air, was questioned by police on 8 February over a complaint of assault.
Police said he had been in an argument with an unidentified woman in a parked car in the Hancock Park area of Los Angeles, which escalated after they left the vehicle.
Both Brown and Rihanna pulled out of that night's Grammy awards, where they had been due to perform.
He has since said he was "sorry and saddened" by the incident and was seeking counselling.
After reports of the assault emerged, a photograph was posted on a US gossip website which purported to show Rihanna with welts, scratches, bruises and swelling on her face.
After it appeared, the Los Angeles Police Department launched an internal investigation and asked for the public's help in finding the person who leaked it.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.