This study explored mediating pathways, moderating factors, and moderated mediation effects of a web-based, cognitive behavioral therapy (CBT) intervention for chronic pain patients with aberrant drug-related behavior (ADRB). In a 2-arm RCT, patients with chronic pain who screened positive for ADRB received treatment-as-usual (TAU, n = 55) or TAU plus a 12-week, web-based CBT intervention (n = 55). Assessments were conducted at weeks 4, 8, and 12, and at 1- and 3-months post intervention. Web-CBT significantly reduced pain catastrophizing, which, in turn, reduced pain interference and pain severity via a pathway of pain catastrophizing. Web-CBT also significantly reduced ADRB both directly and indirectly by reducing pain catastrophizing. For pain interference and pain severity, web-CBT was more effective than TAU for younger patients (≤ age 50). For pain severity, web-CBT was more effective for both younger patients (≤ age 50), and those with a lifetime substance use disorder. Findings suggest that web-CBT’s positive impact on pain outcomes and ADRB are mediated by its effect on pain catastrophizing, and its treatment effects may be most robust for younger patients and those with histories of substance dependence.