Chronic intermittent hypoxia (CIH) induces oxidative stress in the brain, causing sleep disorders. Herein, we investigated the role of pterostilbene (Pte) in CIH-mediated oxidative stress in the brain tissue. A CIH mouse model was constructed by alternately reducing and increasing oxygen concentration in a sealed box containing the mouse; brain tissue and serum were then collected after intragastric administration of Pte. Neurological function was evaluated through field experiments. The trajectory of the CIH mice to the central region initially decreased and then increased after Pte intervention. Pte increased the number of neuronal Nissl bodies in the hippocampus of CIH mice, upregulated the protein levels of Bcl-2, occludin, and ZO-1 as well as the mRNA and protein levels of cAMP-response element binding protein (CREB) and p-BDNF, and reduced the number of neuronal apoptotic cells, Bax protein levels, IBA-1, and GFAP levels. Simultaneously, Pte reversed the decreased levels of superoxide dismutase (SOD), glutathione peroxidase (GSH-PX), and BDNF and increased levels of malondialdehyde (MDA) in the serum of CIH mice. Pte increased Th2 cells, Treg cells, IL-4, IL-10, and TGF-β1 levels and decreased Th1 cells, Th17 cells, IFN-γ, IL-6, and IL- 17A levels in activated BV2 cells and hippocampus in CIH mice. The protein levels of p-ERK1/2, TLR4, p-p38, p-p65, and Bax, apoptosis rate, MDA concentration, Bcl-2 protein level, cell viability, and SOD and GSH-PX concentrations decreased after the activation of BV2 cells. Pte inhibited gliocytes from activating T-cell immune imbalance through p-ERK signaling to alleviate oxidative stress injury in nerve cells.