The use of illicit substances continues to pose a substantial threat to global health, affecting millions of individuals annually. Evidence suggests the existence of a ‘brain–gut axis’ as the involving connection between the central nervous system and gut microbiome (GM). Dysbiosis of the GM has been associated with the pathogenesis of various chronic diseases, including metabolic, malignant, and inflammatory conditions. However, little is currently known about the involvement of this axis in modulating the GM in response to psychoactive substances. In this study, we investigated the effect of MDMA (3,4-methylenedioxymethamphetamine, “Ecstasy”)-dependence on the behavioral and biochemical responses, and the diversity and abundance of the gut microbiome in rats post-treated (or not) with aqueous extract ofAnacyclus pyrethrum(AEAP), which has been reported to exhibit anticonvulsant activity. The dependency was validated using the conditioned place preference (CPP) paradigm, behavioral, and biochemical tests, while the gut microbiota was identified using matrix-assisted laser desorption ionization–time of flight mass spectrometry (MALDI-TOF MS). The CPP and behavioral tests confirmed the presence of MDMA withdrawal syndrome. Interestingly, treatment with AEAP led to a compositional shift in the GM compared to the MDMA-treated rats. Specifically, the AEAP group yielded a higher relative abundance ofLactobacillusandBifidobacter, while animals receiving MDMA had higher levels ofE. coli. These findings suggest thatA. pyrethrumtherapy may directly modulate the gut microbiome, highlighting a potential target for regulating and treating substance use disorders.