"Teen Mom" star Amber Portwood won't be heading to prison ... yet -- because a judge just gave the MTV reality star one last chance to clear her name ... by entering rehab.
TMZ broke the story ... Amber struck a plea deal with prosecutors in her drug case last month -- a deal that would allow Amber to avoid a 5-year prison sentence by completing a court-mandated drug rehabilitation program. An Indiana judge approved the deal today.
If Amber successfully completes the Madison County Drug Court program, her drug case will be entirely dismissed -- but if she screws up, she'll be thrown in the slammer.
As we first reported, Amber was arrested in December for drug possession and failing to provide a urine sample (a stipulation of her probation).
Amber will remain in custody pending a full evaluation by the Drug Court team -- which we're told could take up to two weeks. Once accepted into the program, the judge will release her.