This study mainly investigated the effects of berberine (BBR) on the bile acid metabolism in gut-liver axis and the microbial community in large intestine of weaned piglets challenged with enterotoxigenic Escherichia coli (ETEC) by microbiome and metabolome analyses. Sixty-four piglets were randomly assigned to four groups including Control group, BBR group, ETEC group, and BBR + ETEC group. Dietary BBR supplementation upregulated the colonic mRNA expression of Occludin, Claudin-5, trefoil factor 3 (TFF3), and interleukin (IL)-10, and downregulated colonic IL-1β and IL-8 mRNA expression in piglets challenged with ETEC K88 (p < 0.05). The hepatic non-targeted metabolome results showed that dietary BBR supplementation enriched the metabolic pathways of primary bile acid biosynthesis, tricarboxylic acid cycle, and taurine metabolism. The hepatic targeted metabolome analyses showed that BBR treatment increased the hepatic concentrations of taurocholic acid (TCA) and taurochenodeoxycholic acid (TDCA), but decreased the hepatic cholic acid (CA) concentration (p < 0.05). Further intestinal targeted metabolome analyses indicated that the deoxycholic acid (DCA), hyocholic acid (HCA), 7-ketodeoxycholic acid (7-KDCA), and the unconjugated bile acid concentrations in ileal mucosa was decreased by dietary BBR treatment (p < 0.05). Additionally, BBR treatment significantly upregulated the hepatic holesterol 7 α-hydroxylase (CYP7A1) and sterol 27-hydroxylase (CYP27A1) mRNA expression, and upregulated the ileal mRNA expression of farnesoid X receptor (FXR) and apical sodium-dependent bile acid transporter (ASBT) as well as the colonic mRNA expression of FXR, fibroblast growth factor19 (FGF19), takeda G protein-coupled receptor 5 (TGR5) and organic solute transporters beta (OST-β) in piglets (p < 0.05). Moreover, the microbiome analysis showed that BBR significantly altered the composition and diversity of colonic and cecal microbiota community, with the abundances of Firmicutes (phylum), and Lactobacillus and Megasphaera (genus) significantly increased in the large intestine of piglets (p < 0.05). Spearman correlation analysis showed that the relative abundances of Megasphaera (genus) were positively correlated with Claudin-5, Occludin, TFF3, and hepatic TCDCA concentration, but negatively correlated with hepatic CA and glycocholic acid (GCA) concentration (p < 0.05). Moreover, the relative abundances of Firmicute (phylum) and Lactobacillus (genus) were positively correlated with hepatic TCDCA concentration (p < 0.05). Collectively, dietary BBR supplementation could regulate the gut microbiota and bile acid metabolism through modulation of gut-liver axis, and attenuate the decreased intestinal tight junction expression caused by ETEC, which might help maintain intestinal homeostasis in weaned piglets.