The son of actor Ryan O'Neal and the late Farrah Fawcett has been ordered to spend a year in intense rehab after pleading no contest Wednesday to heroin possession.

RELATED: 15 Celebrity Rehab Repeat Offenders

Los Angeles Superior Court Judge Keith Schwartz also sentenced 26-year-old Redmond O'Neal to serve five years on probation.

District Attorney's spokeswoman Jane Robison says O'Neal could be sent to prison for up to three years if he violates probation.

RELATED: Ryan O'Neal Reveals His Son Redmond is Still Mourning Mom Farrah Fawcett

Redmond O'Neal also pleaded no contest to being a felon in possession of a firearm when he was arrested Aug. 2 after a traffic stop. Ryan O'Neal attended his son's sentencing Wednesday.

Attorney Richard Pintal, who represented the younger O'Neal, says the sentence recognizes that his client is facing serious addiction and medical issues and that treatment was more appropriate.

REALTED: Redmond O'Neal completes drug diversion program