A North Tonawanda man agreed Wednesday to risk up to 18 years in prison in order to receive drug treatment and avoid a felony conviction.

James Thomas, 27, of Roberts Drive, admitted to having more than 0.4 ounces of cocaine in his home on Dec. 18, 2018, and March 15, which police discovered after executing search warrants.

Thomas pleaded guilty to two counts of third-degree criminal possession of a controlled substance, which carries a penalty of up to nine years in prison. But if he completes an 18- to 24-month diversion program for substance abuse disorder, Thomas will have his convictions reduced to misdemeanor drug possession and will be sentenced to no more than three years of probation.