Objective measurements of pain and safe methods to alleviate it could revolutionize medicine. This study used functional near-infrared spectroscopy (fNIRS) and virtual reality (VR) to improve pain assessment and explore non-pharmacological pain relief in cancer patients. Using resting-state fNIRS (rs-fNIRS) data and multinomial logistic regression (MLR), we identified brain-based pain biomarkers and classified pain severity in cancer patients. Participants included healthy individuals who underwent rs-fNIRS recording without VR (Group A), cancer patients who underwent rs-fNIRS recording both before and after engaging in the Oceania relaxation program VR intervention (Group B), and cancer patients who underwent rs-fNIRS recording without VR (Group C). All participants wore a wireless fNIRS headcap for brain activity recording. Pain severity was self-reported by patients using the FACES Pain Scale-Revised (FPS-R). fNIRS data were analyzed with MLR, categorizing pain into no/mild (0–4/10), moderate (5–7/10), and severe (8–10/10) levels. The MLR model classified pain severity in an unseen test group, selected using the leave-one-participant-out technique and repeated across all participants, achieving an accuracy of 74%. VR significantly reduced pain intensity (Wilcoxon signed-rank test, P textless 0.001), with significant changes in brain functional connectivity patterns (P textless 0.05). Additionally, 75.61% of patients experienced pain reductions exceeding the clinically relevant threshold of 30%. These findings underscore the potential of fNIRS for pain assessment and VR as a useful non-pharmacological intervention for cancer-related pain management, with broader implications for clinical pain management.