Robert Downey Jr. says prison may have saved his life -- explaining to a judge that he's 100% rehabilitated from his drug addiction ... and says his time behind bars helped get him on the right path.
The "Iron Man" star wrote a letter to an L.A. County Superior Court judge asking him to consider giving him a formal pardon for the drug convictions he racked up between '96 and '02.
In the letter, obtained by TMZ, Downey starts off:
"My reason for asking that I be granted a Certificate of Rehabilitation is twofold, prompted in part by the extremely fortunate position I have found myself in since 2004, when I fully accepted responsibility for my addiction."
"First, it is to spare my family the unfavorable conditions a father and husband convicted of felony charges often (and sometimes rightly) faces."
"Second, I can now say without reservation that I am rehabilitated from my previous condition, that of a practicing addict."
Downey says he credits the 12-step program and Judge Lawrence Mira -- who told him in 1996 that he would lock him up if he violated his probation.
"When I relapsed, I was given the upper term, and served 16 months at Corcoran State Correctional Facility from 1998 to 2000."
Downey says he was able to undergo a "deep personal shift away from the diseased condition that had plagued me for years, cost me my freedom, and prevented the simple and profound privilege of being a productive member of society."
"I do not consider myself a 'role model,' but i sincerely believe the limitations imposed by my past digressions are not in line with the way I have conducted myself in this second life."
Downey says he deserved a pardon -- adding, "I do not feel I am entitled to anything that I have not earned."
Ultimately, the judge was clearly moved by the letter and granted Downey his pardon.