Objective: To determine whether the increase in slow-wave sleep associated with modafinil treatment in chronic cocaine users mediates improved clinical outcomes. Method: 57 cocaine dependent participants were randomized to receive modafinil 400 mg or placebo daily during a period of inpatient treatment followed by six weeks of outpatient treatment. Participants underwent polysomnographic sleep recording during inpatient treatment prior to and after starting modafinil. Outpatient treatment consisted of weekly cognitive behavioral therapy. Contingency management was used to promote participation in treatment and research demands, including thrice weekly visits during the outpatient phase for urine toxicology screens and other assessments. The primary clinical outcome was the percent of urine toxicology screens that were negative for cocaine. Results: Modafinil treatment was associated with a higher mean percentage (52% vs. 26%) of cocaine free urine screens (p = 0.02) and an increase in N3 sleep time (p = 0.002). The change in N3 sleep time mediated the higher rate of cocaine-free urine screens. Modafinil treatment was also associated with more consecutive days abstinent during outpatient treatment, greater survival of abstinence, higher daily rates of abstinence, and less sleep degradation typically associated with abstinence from chronic cocaine use. Conclusions: Morning-dosed modafinil improves slow-wave sleep in abstinent cocaine users in the inpatient setting, and this effect is a statistical mediator of improved clinical outcomes associated with continued modafinil treatment. The high rates of abstinence achieved in this trial suggest that promoting healthy sleep physiology in an inpatient setting may be important in the effective treatment of cocaine dependence. (C) 2015 Elsevier Ireland Ltd. All rights reserved.