Stevie J just avoided going back to jail, but there's a catch ... he's going to rehab instead.
Stevie was in court last week for his child support case so the judge could decide whether to revoke his bail for failing a recent drug test. Luck was on Stevie's side -- instead of locking him up, the judge ordered him to enroll in an outpatient drug treatment program.
Under the order, Stevie must report to a facility twice a week and comply with drug testing.
He has to go back to court next month, and show proof he's been following rehab rules. If he screws up -- jail time will be back in play.