Growing studies show that gut microbiota is closely associated with depression. Acupuncture treatment could regulate the gut microbiota of many diseases. Here, we aim to observe the effect of electroacupuncture (EA) on gut microbiota in rats that showed depressive-like behavior. The rats were randomly divided into normal group, chronic unpredictable mild stress model (CUMS) group, CUMS + electroacupuncture (EA) group, and CUMS + sham-electroacupuncture (Sham) group. The CUMS+EA rats were treated with EA stimulation at bilateral Zusanli (ST36) and Tianshu (ST25) acupoints for 2 weeks (0.7 mA, 2/100 Hz, 30 min/day). The rats in the sham EA group were treated with the same conditions without inserting needles and electrical stimulation. Behavioral tests were conducted by forced swimming test (FST), open field test (OFT), and sucrose preference test (SPT) to assess depression-like behavior in rats. The relative abundance of intestinal bacteria in rat feces was detected by 16S rRNA analysis. The expression of calcitonin-gene-related peptide (CGRP), vasoactive intestinal peptide (VIP), somatostatin (SST), and adrenocorticotropic hormone (ACTH) in serum was detected by ELISA kit, and VIP, CGRP, and SST in the colon were detected by qRT-PCR and Western blot. Chronic unpredictable mild stress model rats exhibited depressive-like behaviors and had differential abundance vs. control rats. CUMS significantly decreased the relative abundance of Bifidobacterium and Streptococcus at the genus level, CGRP in plasma (p < 0.05), and significantly increased the intestine propulsion rate, the mRNA and protein expression of VIP, SST, and mRNA in the colon, and ATCH in plasma (p < 0.05). EA rats with microbial profiles were distinct from CUMS rats. EA markedly reduced the depressive-like behaviors, significantly increased the intestine propulsion rate, the relative abundance of Bacteroidetes, Proteobacteria, and Actinobacteria at the phylum level, Bifidobacterium and Streptococcus at the genus level, and VIP and CGRP in plasma (p < 0.05), and significantly decreased Firmicutes, the ratio of Firmicutes to Bacteroidetes at the phylum level, ACTH and SST in plasma, and SST mRNA in the colon (p < 0.05). The antidepressant effect of EA at ST36 and ST25 is related to regulating intestinal flora and the neurotransmitter system. Our study suggests that EA contributes to the improvement of depression, and gut microbiota may be one of the mechanisms of EA effect.