A South Dublin man kicked out at gardai and tried to bite them when they arrested him during a city centre disturbance.
Jude Sweeney (24) had just been struck by another man and had lost a tooth when gardai arrived on the scene.
He accepted that he had reacted badly.
Judge Kathryn Hutton struck his case out, leaving him without a criminal record, when he made a charity donation.
Sweeney, of Glenomena Grove, Blackrock, Dublin, pleaded guilty to public order offences.
He admitted public intoxication and using threatening, abusive and insulting behaviour to cause a breach of the peace.
Dublin District Court heard that the incident happened at Camden Street at 3am on March 14.
Gardai went to the scene following an earlier call about a disturbance.
They found Sweeney in a very agitated and drunken state, Garda Sergeant Niall Murphy told the court.
Sweeney began "striking out" at gardai and had to be restrained.
While gardai were restraining him, the defendant was kicking out and biting at them.
However, he did not make contact with or bite any of the officers involved, Sgt Murphy said.
Sweeney had no previous convictions of any kind, the court heard.
He had phoned gardai since the incident to apologise to them, his lawyer said.
Before they arrived, Sweeney had received a blow to the mouth from someone and lost a tooth, with two other displaced teeth.
"That was what caused his agitation," his lawyer said.
He added that Sweeney should not have reacted in the way he did but there was a reason behind what happened.
He was apologetic for the offences and had not come to the attention of gardai since.
Sweeney's lawyer asked the judge to be as lenient as she could in the circumstances and to deal with the case "by way of a poor box" contribution.
The accused handed in €200, to be donated to the Merchant's Quay Project, which tackles homelessness and drugs problems in the inner city.
Saying the accused had put forward a good defence, the judge struck the charges out.