The gut microbiota could play a significant role in the progression of nonalcoholic fatty liver disease (NAFLD); however, its relevance in drug-induced liver injury (DILI) remains unexplored. Since the two hepatic disorders may share damage pathways, we analysed the metagenomic profile of the gut microbiota in NAFLD, with or without significant liver fibrosis, and in DILI, and we identified the main associated bacterial metabolic pathways. In the NAFLD group, we found a decrease in Alistipes, Barnesiella, Eisenbergiella, Flavonifractor, Fusicatenibacter, Gemminger, Intestinimonas, Oscillibacter, Parasutterella, Saccharoferementans and Subdoligranulum abundances compared with those in both the DILI and control groups. Additionally, we detected an increase in Enterobacter, Klebsiella, Sarcina and Turicibacter abundances in NAFLD, with significant liver fibrosis, compared with those in NAFLD with no/mild liver fibrosis. The DILI group exhibited a lower microbial bacterial richness than the control group, and lower abundances of Acetobacteroides, Blautia, Caloramator, Coprococcus, Flavobacterium, Lachnospira, Natronincola, Oscillospira, Pseudobutyrivibrio, Shuttleworthia, Themicanus and Turicibacter compared with those in the NAFLD and control groups. We found seven bacterial metabolic pathways that were impaired only in DILI, most of which were associated with metabolic biosynthesis. In the NAFLD group, most of the differences in the bacterial metabolic pathways found in relation to those in the DILI and control groups were related to fatty acid and lipid biosynthesis. In conclusion, we identified a distinct bacterial profile with specific bacterial metabolic pathways for each type of liver disorder studied. These differences can provide further insight into the physiopathology and development of NAFLD and DILI.