Bacillus subtilis (B. subtilis) is a commercially important probiotic known to produce secondary metabolites with antibacterial, antifungal and anti-inflammatory activities. However, the potential ability of B. subtilis to combat viruses, especially DNA viruses, has not been extensively investigated. In this study, we identified two distinct B. subtilis strains and examined the efficiency of their secondary metabolites against pseudorabies virus (PRV), a swine herpesvirus resulting in economic losses worldwide. We found that treatment with the secondary metabolites of B. subtilis L2, but not the metabolites of B. subtilis V11, significantly inhibited PRV replication in multiple cells. Notably, the antiviral activity of the metabolites of B. subtilis L2 was thermal stable, resistant to protease digestion. Moreover, these metabolites effectively impeded PRV binding, entry and replication. Importantly, oral administration of the metabolites of B. subtilis L2 protected mice from lethal PRV infection, rescuing weight loss and reducing the viral load in vivo. In summary, our results reveal that the metabolites of B. subtilis L2 exhibit anti-PRV activity both in vitro and in vivo, providing a potential candidate for novel antiviral drugs.