To investigate the effect of 5-aminolevulinic acid (5-ALA) on in vitro rumen gas production, fermentation characteristics, and bacterial community profiles, five levels of 5-ALA (0, 100, 500, 1000, and 5000 mg/kg DM) were supplemented into a total mixed ration (concentrate/forage = 40:60) as substrate in an in vitro experiment. Results showed that as the supplementation level of 5-ALA increased, asymptotic gas production (b) decreased linearly and quadratically (p < 0.01) while the dry matter degradation rate increased quadratically (p < 0.01). Meanwhile, the propionate concentration of 72 h incubation fluid increased linearly (p = 0.03) and pH value increased linearly and quadratically (p < 0.01), while the concentrations of butyrate, isobutyrate, valerate, isovalerate, and NH3-N and the ratio of acetate/propionate (A/P) decreased linearly and quadratically (p < 0.05). There was no significant difference in any alpha diversity indices of bacterial communities among the various 5-ALA levels (p < 0.05). PCoA and PERMANOVA analysis revealed that the bacterial profiles showed a statistical difference between the treatment 5-ALA at 1000 mg/kg DM and the other levels except for 5000 mg/kg DM (p < 0.05). Taxonomic classification revealed a total of 18 and 173 bacterial taxa at the phylum and genus level with relative abundances higher than 0.01% in at least half of the samples, respectively. LEfse analysis revealed that 19 bacterial taxa were affected by 5-ALA levels. Correlation analysis showed that Actinobacteriota was positively correlated with the gas production parameter b, the ratio of A/P, and the concentration of butyrate, isovalerate, and NH3-N (p < 0.05) and negatively correlated with pH (p < 0.05). WPS-2 exhibited a negative correlation with the gas production parameter b, the ratio of A/P, and the concentration of butyrate, valerate, isobutyrate, isovalerate, and NH3-N (p < 0.05), along with a weaker positive correlation with pH (p = 0.04). The Bacteroidales BS11 gut group was negatively correlated with the concentration of propionate but positively correlated with gas production parameter b and the concentration of butyrate and NH3-N (p < 0.05). The Lachnospiraceae NK3A20 group was found to have a positive correlation with gas production parameter b, the ratio of A/P, and the concentration of butyrate, isobutyrate, isovalerate, valerate, total VFA, and NH3-N (p < 0.05), but a highly negative correlation with pH (p < 0.01). Differential metabolic pathways analysis suggested that metabolic pathways related to crude protein utilization, such as L-glutamate degradation VIII (to propanoate), L-tryptophan degradation IX, and urea cycle, increased with 5-ALA levels. In summary, including 5-ALA in the diet might improve energy and protein utilization by reducing the abundance of Actinobacteriota, the Bacteroidales BS11 gut group, the Lachnospiraceae NK3A20 group, and certain pathogenic bacteria and increasing the abundance of WPS-2.