Background Slow transit constipation (STC) is caused by intestinal peristalsis dysfunction and is closely associated with disturbance of the intestinal microecological balance. Bacillus subtilis plays a positive role in the treatment of STC, but its mechanism needs to be further explored. Aims The purpose of the present study was to explore the effects and mechanism of B. subtilis on the pathophysiology of STC. Methods A STC mouse model was established with compound diphenoxylate, following which B. subtilis was used to treat STC. The effects and possible mechanism of B. subtilis on STC were investigated by assessing intestinal motility, histology of the colon, release of 5-HT in enterochromaffin cells (ECs) and the TGR5/TRPA1 pathway. Moreover, LC-MS targeted metabolomics was used to analyze the regulation of Bacillus subtilis on bile acid metabolisms in STC mice. Results Bacillus subtilis significantly increased 24 h defecations, fecal moisture and intestinal transport rate of STC mice, improved pathological damage of the colon and showed protective effects on the intestinal tract. The release of 5-HT from ECs and the bile acid receptor TGR5/TRPA1 pathway were significantly increased in STC mice treated with B. subtilis. In addition, the metabolomics results showed that the bile acid contents of STC mice were significantly decreased, and B. subtilis could increase the bile acid composition and content of STC mice. Conclusion Bacillus subtilis regulates intestinal peristalsis of STC by promoting the release of 5-HT from ECs through bile acid metabolism and its receptor TGR5 pathway and plays a positive role in the treatment of STC.