Using an alternative bio-product is one of the most promising ways to control bovine mastitis and avoid new intra-mammary infections. The aims of this study were to ascertain the prevalence of biofilm-forming bacteria responsible for causing clinical mastitis in dairy herds and to assess the effectiveness of bacteriocins, produced byBacillus subtilis, in controlling the growth of these bacteria in the milk of animals. A total of 150 milk samples were collected from cows and buffalos suffering from mastitis and the etiological agents were isolated and identified by the VITEK-2-COMPACT-SYSTEM®. Additionally, the capability of the bacterial isolates to produce biofilms was determined. RT-PCR was used to detect enterotoxin-producing genes (sedandseb), resistance genes (mecAandblaZ), and biofilm-associated genes (icaAandfnbA) in the isolated bacteria. The susceptibility patterns of the bacterial isolates to bacteriocins were assessed using an agar well-diffusion assay.S. aureuswas significantly more capable of producing biofilms than coagulase-negativeStaphylococcusisolates.S. ubriswas the strongest biofilm producer among theStreptococcusspecies. The sensitivity profiles of theStaphylococcusspp. (S. aureusand coagulase-negativeStaphylococcus) and their biofilm producers to bacteriocins were significantly higher (100% and 90%, respectively) at the same concentration. Bacteriocins had a lethal effect onStaphylococci,Streptococci, and biofilm development at a dose of 250 µg/mL. In dairy farms, bacteriocins are a viable alternative treatment for the prevention and control of bovine clinical mastitis.Supplementary InformationThe online version contains supplementary material available at 10.1007/s00284-023-03324-x.