One way to improve treatment effects of chronic pain is to identify and improve control over mechanisms of therapeutic change. One treatment approach that includes a specific proposed mechanism is acceptance and commitment therapy (ACT) with its focus on increasing psychological flexibility (PF). The aim of the present study was to examine the role of PF as a mechanism of change in ACT. This is based on mediation analyses of data from a previously reported randomized controlled trial, evaluating the effectiveness of an ACT-based online intervention for chronic pain (ACTonPain). We performed secondary analyses on pretreatment, posttreatment, and follow-up data from 302 adults, receiving a guided (n = 100) or unguided (n = 101) version of ACTonPain, or allocated to the waitlist control group (n = 101). Structural equation modelling and a bias-corrected bootstrap approach were applied to examine the indirect effects of the treatment through pretreatment and posttreatment changes in the latent construct reflecting PF. The latent construct consisted of data from the Chronic Pain Acceptance Questionnaire and the Acceptance and Action Questionnaire. The outcomes were pretreatment to follow-up changes in pain interference, anxiety, depression, pain, and mental and physical health. Structural equation modelling analyses revealed that changes in PF significantly mediated pretreatment to follow-up changes in all outcomes in the intervention groups compared with waitlist (standardized estimates ranged from I0.16I to I0.69I). Global model fit yielded modest but acceptable results. Findings are consistent with the theoretical framework behind ACT and contribute to growing evidence, supporting a focus on PF to optimize treatment effects.