Remifentanil-induced hyperalgesia (RIH) is a common clinical phenomenon that limits the use of opioids in pain management. Esketamine, a non-competitive N-methyl-d-aspartate (NMDA) receptor antagonist, has been shown to prevent and treat RIH. However, the underlying effect mechanism of esketamine on RIH remains unclear. This study aimed to investigate the role and mechanism of esketamine in preventing and treating RIH based on the NMDA receptor–CaMKIIα pathway. In this study, an experimental animal model was used to determine the therapeutic effect of esketamine on pain elimination. Moreover, the mRNA transcription and protein expression levels of CaMKII and GluN2B were investigated to offer evidence of the protective capability of esketamine in ameliorating RIH. The results demonstrated that esketamine attenuated RIH by inhibiting CaMKII phosphorylation and downstream signaling pathways mediated by the NMDA receptor. Furthermore, ketamine reversed the upregulation of spinal CaMKII induced by remifentanil. These findings suggest that the NMDA receptor–CaMKII pathway plays a critical role in the development of RIH, and ketamine’s effect on this pathway may provide a new therapeutic approach for the prevention and treatment of RIH.