• Fermented apple juice alleviates the diarrhea induced by ceftriaxone sodium. • Fermented apple juice improved the destroyed gut microbiota of mice. • There were 136 significantly changed compounds identified in fermented apple juice compared to unfermented apple juice. • Five bioactive compounds are partly responsible for the fermented apple juice performances. This study aimed to optimize the fermentation conditions of apple juice by Lactobacillus plantarum to obtain fermented apple juice (FAJ) with high probiotic content and tannic acid content. The apple juice and FAJ compounds were identified and relatively quantified by UHPLC-ESI-Q TRAP-MS/MS. Treating mice with ceftriaxone sodium induced diarrhea. However, ingestion of FAJ helped alleviate these symptoms. Furthermore, via 16S rRNA sequencing, FAJ reduced the proportion of Bacillota to Bacteroidota at the phyla level. Moreover, at the genus level, FAJ also caused a lower relative abundance of Enterococcus and Clostridium , and a higher relative abundance of Lactobacillus and Prevotella . Additionally, FAJ improved the intestinal morphology and intestinal barrier function. Five up-regulated bioactive compounds ( l -isoleucine, l -leucine, l -valine, 4-Guanidinobutyric acid, and Phenyllactate) are partly responsible for the performances of FAJ. All these findings implied that FAJ could be a dietary supplement for lessening antibiotic-associated diarrhea by regulating intestinal microbiota and barrier function.