The gut microbial community is closely related to mastitis, but studies regarding the influences of mastitis on gut microbiota in buffalo remain scarce. Herein, we characterized the differences in gut bacterial and fungal communities between mastitis-affected and healthy buffalos. Interestingly, although mastitis had no effect on gut bacterial and fungal diversities in the buffalos, some bacterial and fungal taxa were significantly altered. Bacterial and fungal taxonomic analysis showed that the preponderant bacterial phyla (Firmicutes and Bacteroidetes) and fungal phyla (Ascomycota and Basidiomycota) in buffalo were the same regardless of health status. At the level of genus, the changes in some gut bacterial and fungal abundances between both groups were gradually observed. Compared with healthy buffalos, the proportions of 3 bacterial genera (uncultured_bacterium_f_Muribaculaceae, Eubacterium_nodatum_group, and Lachnoclostridium_10) and 1 fungal genus (Pichia) in the mastitis-affected buffalo were significantly increased, whereas 4 bacterial genera (Ruminococcus_2, Candidatus_Stoquefichus, Turicibacter, and Cellulosilyticum) and 4 fungal genera (Cladosporium, Thermothelomyces, Ganoderma and Aspergillus) were significantly decreased. Taken together, this research revealed that there was significant difference in the compositions of the gut microbial community between the healthy and mastitis-affected buffalos. To our knowledge, this is the first insight into the characteristics of the gut microbiota in buffalos with mastitis, which is beneficial to understand the gut microbial information of buffalo in different health states and elucidate the pathogenesis of mastitis from the gut microbial perspective.