Mastitis is one of the most prevalent diseases in dairy farming worldwide. The gut microbiota plays an important role in the regulation of systemic and local inflammatory diseases, such as mastitis. However, the regulatory mechanism of the gut microbiota on mastitis is still unclear. Thus, the aim of this study was to investigate the function and regulatory mechanisms of the gut microbiota in host defense against mastitis caused by Staphylococcus aureus (S. aureus) infection. Increased blood-milk barrier permeability, and S. aureus-induced mastitis severity were observed gut microbiota-dysbiosis mice compared with those in control mice. Moreover, feces microbiota transplantation (FMT) to microbbiota-dysbiosis mice reversed these effects. Furthermore, established disruption of commensal homeostasis results in significantly increased abundance of pathogenic Enterobacter bacteria, while the relative abundance of short-chain fatty acid (SCFAs)-producing bacterial phyla (Firmicutes and Bacteroidetes) was significantly reduced. However, FMT to gut microbiota-dysbiosis mice reversed these changes. In addition, dysbiosis reduced the levels of SCFAs, and administration of sodium propionate, sodium butyrate, and probiotics (butyrate-producing bacteria) reversed the changes in the blood-milk barrier and reduced the severity of mastitis induced by S. aureus. In conclusion, this new finding demonstrated that the gut microbiota acts as a protective factor in host defense against mastitis and that targeting the gut-mammary gland axis represents a promising therapeutic approach for mastitis treatment.