Abstract Background Alcohol drinking and gut microbiota are related to hepatocellular carcinoma (HCC), but the specific relationship between them remains unclear. Aims We aimed to establish the alcohol drinking-gut microbiota-liver axis and develop machine learning (ML) models in predicting the occurrence of early-stage HCC. Methods Two hundred sixty-nine patients with early-stage HCC and 278 controls were recruited. Alcohol drinking-gut microbiota-liver axis was established through the mediation/moderation effect analyses. Eight ML algorithms including Classification and Regression Tree (CART), Gradient Boosting Machine (GBM), K-Nearest Neighbor (KNN), Logistic Regression (LR), Neural Network (NN), Random Forest (RF), Support Vector Machine (SVM), and eXtreme Gradient Boosting (XGBoost) were applied. Results A total of 160 pairs of individuals were included for analyses. The mediation effects of Genus_Catenibacterium (P = 0.024), Genus_Tyzzerella_4 (P < 0.001), and Species_Tyzzerella_4 (P = 0.020) were discovered. The moderation effects of Family_Enterococcaceae (OR = 0.741, 95%CI:0.160–0.760, P = 0.017), Family_Leuconostocaceae (OR = 0.793, 95%CI:0.486–3.593, P = 0.010), Genus_Enterococcus (OR = 0.744, 95%CI:0.161–0.753, P = 0.017), Genus_Erysipelatoclostridium (OR = 0.693, 95%CI:0.062–0.672, P = 0.032), Genus_Lactobacillus (OR = 0.655, 95%CI:0.098–0.749, P = 0.011), Species_Enterococcus_faecium (OR = 0.692, 95%CI:0.061–0.673, P = 0.013), and Species_Lactobacillus (OR = 0.653, 95%CI:0.086–0.765, P = 0.014) were uncovered. The predictive power of eight ML models was satisfactory (AUCs:0.855–0.932). The XGBoost model had the best predictive ability (AUC = 0.932). Conclusions ML models based on the alcohol drinking-gut microbiota-liver axis are valuable in predicting the occurrence of early-stage HCC. Graphical Abstract