Electroacupuncture (EA) is a widely recognized therapy for depression and sleep disorders in clinical practice, but its efficacy in the treatment of comorbid insomnia and depression remains uncertain. To assess the efficacy and safety of EA as an alternative therapy in improving sleep quality and mental state for patients with insomnia and depression. A 32-week patient- and assessor-blinded, randomized, sham-controlled clinical trial (8-week intervention plus 24-week observational follow-up) was conducted from September 1, 2016, to July 30, 2019, at 3 tertiary hospitals in Shanghai, China. Patients were randomized to receive EA treatment and standard care, sham acupuncture (SA) treatment and standard care, or standard care only as control. Patients were 18 to 70 years of age, had insomnia, and met the criteria for depression as classified in the Diagnostic and Statistical Manual of Mental Disorders (Fifth Edition). Data were analyzed from May 4 to September 13, 2020. All patients in the 3 groups were provided with standard care guided by psychiatrists. Patients in the EA and SA groups received real or sham acupuncture treatment, 3 sessions per week for 8 weeks, for a total of 24 sessions. The primary outcome was change in Pittsburgh Sleep Quality Index (PSQI) from baseline to week 8. Secondary outcomes included PSQI at 12, 20, and 32 weeks of follow-up; sleep parameters recorded in actigraphy; Insomnia Severity Index; 17-item Hamilton Depression Rating Scale score; and Self-rating Anxiety Scale score. Among the 270 patients (194 women [71.9%] and 76 men [28.1%]; mean [SD] age, 50.3 [14.2] years) included in the intention-to-treat analysis, 247 (91.5%) completed all outcome measurements at week 32, and 23 (8.5%) dropped out of the trial. The mean difference in PSQI from baseline to week 8 within the EA group was -6.2 (95% CI, -6.9 to -5.6). At week 8, the difference in PSQI score was -3.6 (95% CI, -4.4 to -2.8; P < .001) between the EA and SA groups and -5.1 (95% CI, -6.0 to -4.2; P < .001) between the EA and control groups. The efficacy of EA in treating insomnia was sustained during the 24-week postintervention follow-up. Significant improvement in the 17-item Hamilton Depression Rating Scale (-10.7 [95% CI, -11.8 to -9.7]), Insomnia Severity Index (-7.6 [95% CI, -8.5 to -6.7]), and Self-rating Anxiety Scale (-2.9 [95% CI, -4.1 to -1.7]) scores and the total sleep time recorded in the actigraphy (29.1 [95% CI, 21.5-36.7] minutes) was observed in the EA group during the 8-week intervention period (P < .001 for all). No between-group differences were found in the frequency of sleep awakenings. No serious adverse events were reported. In this randomized clinical trial of EA treatment for insomnia in patients with depression, quality of sleep improved significantly in the EA group compared with the SA or control group at week 8 and was sustained at week 32. ClinicalTrials.gov Identifier: NCT03122080.