Actor Shia LaBeouf pleaded guilty to disorderly conduct after getting arrested in June for his erotic behavior during the Broadway musical "Cabaret."

ABC News reported that the 28-year-old "Transformers" actor appeared in Manhattan Criminal Court Wednesday and pleaded guilty to disorderly conduct, but his case will reportedly be dismissed if the actor stays out of trouble for six months and completes a three month treatment program for substance abuse.

"Are you pleading guilty because you are guilty?" Judge Diana Boyar asked LaBeouf, to which he answered, "Yes, your honor," ABC News reported.

The judge also told LaBeouf that he must have no new arrests for the next six months. If he follows through with the agreement, the court will then withdraw his plea and have the arrest erased from his record.

"You must come to court each time the case is on. There must be no new arrests [or] all bets are off," Judge Boyar warned the troubled actor.

According to ABC News, Assistant District Attorney Alyssa Russell told the judge that prosecutors made the plea deal "based on the fact that the defendant has been in continuous treatment since his arrest."

"We appreciate the thoughtfulness of the resolution of the matter by the (Manhattan) district attorney's office," LaBeouf's lawyer, G. Robert Gage, said while leaving the court room. LaBeouf actor declined to comment.

In June, the former child star was arrested in New York City while attending a performance of "Cabaret," starring Michelle Williams and Alan Cumming. Us Weekly reported that LaBeouf was accused of smoking inside the theater and "engaged in disruptive behavior" during the show by slapping strangers on the rear end and yelling at audience members and the actors on stage.

He was also accused of refusing to leave the theater and spitting on a police officer's feet, while being escorted out of the theater. LaBeouf had been charged with "two counts of disorderly conduct and one count of criminal trespassing."