Acupuncture can reduce cognitive deficits in Alzheimer’s disease. However, whether electroacupuncture can prevent or alleviate the cognitive deficits in animal models of aging remains poorly understood. Studies have shown that disordered epigenetic modifications play a critical role in age-related cognitive decline. Therefore, we hypothesized that preventive electroacupuncture might improve cognitive functions during aging by regulating epigenetic modifications. A rat model of aging was produced by intraperitoneal injection of 120 mg/kg D-galactose for 8 weeks. Baihui and Shenshu acupoints were stimulated by electroacupuncture for 8 weeks from the first day of D-galactose administration. Preventive electroacupuncture alleviated memory impairment, decreased tau hyperphosphorylation, and reduced glycogen synthase kinase-3β protein and mRNA expression levels in the brainstem dorsal raphe nucleus, where intracellular neurofibrillary tangle lesions first occur. In addition, the DNA methylation level in the promoter region of the glycogen synthase kinase-3β gene was increased. The effects of preventive electroacupuncture were stronger than those of preventive acupuncture. Intraperitoneal injection of 0.4 mg/kg 5-aza-2′-deoxycytidine, an inhibitor of DNA methyltransferase that blocks epigenetic modifications, antagonized the effects of preventive electroacupuncture. Our results suggest that preventive electroacupuncture treatment alleviates cognitive impairment in aging rats probably by affecting the epigenetic modification of the glycogen synthase kinase-3β gene in the dorsal raphe nucleus. This study was approved by the Animal Ethics Committee of Hubei University of Chinese Medicine, China (approval No. HUCMS201712001) on November 28, 2017.