Garrett, 48, was arrested in February after authorities found him carrying heroin in a Los Angeles subway station.
He has had a series of drug arrests since the height of his popularity in the 1970s.
The case could be dismissed if Garrett completes the terms of the treatment program within 18 months.
"I just think this is in everybody's best interests," said Garrett's attorney, Andrew Flier. He said he was proud of Garrett for entering the plea and recognizing that he needs additional treatment.
Garrett has been working with celebrity addiction specialist Dr. Drew Pinsky and he is among those slated to appear on the next season of "Celebrity Rehab With Dr. Drew," Flier said. Garrett's court-ordered program wouldn't be part of any reality show, he said.