To observe the effects of electroacupuncture (EA) on sleep quality, sleep structure, and cognitive function in patients with insomnia related to cerebral infarction, and to explore the brain effect mechanism of EA on insomnia related to cerebral infarction. Thirty-six patients with insomnia related to cerebral infarction were randomly divided into an EA group (18 cases, 1 case was eliminated and 1 case dropped out) and a sham acupuncture group (18 cases, 1 case was eliminated and 2 cases dropped out). Both groups received conventional treatment for cerebral infarction. The EA group received EA at Sishencong (EX-HN 1) with continuous waves at a frequency of 2 Hz, at an intensity tolerable to the patient. The sham acupuncture group received sham acupuncture at non-acupoints with the same EA parameters but electrical stimulation was interrupted after 30 s. Both groups were treated for 20 min each session, once daily, 5 days per week, for a total of 4 weeks. Pittsburgh sleep quality index (PSQI), Montreal cognitive assessment-basic (MoCA-B) scores, and short-term memory (STM) encoding test accuracy and average reaction time were observed before and after treatment in the two groups. Polysomnography (PSG) was used to evaluate sleep structure, and electroencephalogram (EEG) data were collected to observe the standardized power value of the Theta frequency band before and after treatment. Compared with before treatment, PSQI score was decreased and MoCA-B score was increased in the EA group after treatment (P<0.001); the EA group had lower PSQI score and higher MoCA-B score than those in the sham acupuncture group (P<0.001, P<0.01). Compared with before treatment, STM encoding test accuracy was increased and average reaction time was shortened in the EA group after treatment (P<0.01, P<0.001); sleep efficiency (SE) was increased (P<0.01), total sleep time (TST), REM, and N3 stages were prolonged (P<0.01, P<0.05), and sleep latency (SL) was shortened (P<0.01). The standardized power value of the Theta frequency band in EEG channels F3, C3, C4, O1 and O2 was decreased (P<0.05). After treatment, the EA group had higher STM encoding test accuracy, shorter average reaction time (P<0.05), higher SE (P<0.01), longer TST, REM and N3 stages (P<0.01), and shorter SL (P<0.01) than those in the sham acupuncture group. There was no statistically significant difference in the standardized power value of the Theta frequency band between the two groups (P>0.05). EA could regulate sleep quality and structure in patients with insomnia related to cerebral infarction, and improve cognitive function, possibly related to the reduction of slow-wave activity in EEG.