Background: The widespread prevalence of chronic pain (CP) significantly impacts daily functioning worldwide. In mainland China, maintaining engagement in biopsychosocial interventions remains challenging. Gamification, designed based on self-determination theory, can enhance motivation, while machine learning (ML) algorithms can assist clinicians in dynamically optimizing pain management. Objective: This study aimed to (1) evaluate the preliminary effectiveness of a gamified pain management (GPM) program on CP and psychological outcomes and (2) identify key factors of significant pain improvements through the application of ML to guide intervention adjustments. Methods: A single-arm, pre-post study was conducted with 16 participants with CP in mainland China, recruited via social media using convenience sampling. Participants engaged in a 10-week web-based GPM intervention consisting of education, physical activities, and gamified elements, including points, avatars, and feedback. Primary outcomes were pain intensity and interference measured by the Brief Pain Inventory. Secondary outcomes included anxiety, depression, and quality of life. Analysis included paired tests, and ML models were trained to predict clinically meaningful pain reductions. Shapley additive explanations, least absolute shrinkage and selection operator regression, association rule mining, and Kaplan-Meier survival analysis were used to identify key predictors and optimal sessions and intervention durations across subgroups. Results: A total of 16 participants were engaged, with a mean age of 27.63 (SD 9.584) years. Results from paired tests reported significant improvements in pain intensity (decreased by 27.3%, 95% CI 1.061 to 3.064; =.001), pain interference (decreased by 27.3%, 95% CI 8.159-17.216; <.001), and psychological distress, including anxiety (=3.538, 95% CI 0.969 to 3.906; =.003) and depression (=4.559, 95% CI 2.230 to 6.145; <.001). The gradient boosting model demonstrated the highest predictive accuracy (area under the curve=0.89 and accuracy=0.82). Least absolute shrinkage and selection operator regression identified session 3 (β=−0.45, 95% CI −0.68 to −0.22; <.001) and session 5 (β=−0.32, 95% CI −0.59 to −0.05; =.02) as most predictive of clinical success, while association rule mining revealed effective session combinations for different patient subgroups. Time-to-event analyses indicated that individuals with low back pain and higher baseline severity required longer intervention durations for improvement (5 wk; =.03). Conclusions: This pilot study presents an innovative method that combines ML with dynamic engagement data from a GPM program during interventions, rather than relying on static baseline data in prior studies. The results show preliminary efficacy and identify specific optimal session combinations and personalized treatment durations for different pain subgroups. These exploratory findings contribute to the field by providing a data-driven method for adaptive, personalized digital health interventions that move beyond one-size-fits-all strategies, potentially enabling clinicians to modify content and dosage to improve engagement and outcomes if validated in larger sample trials. Trial Registration: Chinese Clinical Trial Registry ChiCTR2400094247; https://www.chictr.org.cn/showprojEN.html?proj=245138


