Objective This study aimed to explore the effect and mechanism of remifentanil on cardiopulmonary bypass (CPB)-induced cerebral nerve injury. Methods After pretreating with remifentanil, or dexmedetomidine (DEX), SD rats were subjected to the CPB for 2 h. The data of body temperature, blood gas and mean arterial pressure (MAP) and hematocrit (HCT) were recorded at different time points. The cerebral tissue water content of rats was determined and immunohistochemical (IHC) and H&E assays on the hippocampal CA1 region of rats was performed. The levels of interleukin (IL)-6, IL-10, soluble protein-100β (S100β) and neuron-specific enolase (NSE) were analyzed by ELISA, and those of the indexes for oxidative stress (malondialdehyde (MDA) and superoxide dismutase (SOD)) were detected by the commercial kits. Morris water maze was used to evaluate the learning and memory abilities. Western blot/qRT-PCR were used to detect the protein/mRNA expressions in hippocampus. Results CPB increased the levels/expressions of IL-6, IL-10, S100β, NSE, MDA, cleaved caspase-3, Bax and decreased those of Bcl-2, SOD, p-AKT, HO-1, in serum and parietal cortex tissue, with increased brain water content, lesions in the hippocampal CA1 area, swimming distance, brain nerve injury and decreased escape latency, retention time on platform and times of crossing the platform of rats. The preconditioning of remifentanil or DEX partially attenuated CPB-induced injury and -decreased expressions on p-AKT and HO-1, while further promoting CPB-induced expression of nuclear Nrf2 expression and inhibiting that of cytoplasm Nrf2. Conclusion This paper demonstrates that remifentanil preconditioning could partially attenuate CPB-induced brain nerve injury of rats.