The objectives of this study were to evaluate the antimicrobial capacity of the photosensitizer (PS) safranin-O (Sf), through antimicrobial photodynamic therapy (PDTa), against strains of Pseudomonas fluorescens (PV1, PVh, and PC3) and Staphylococcus aureus (SV1, SV3, SV5, SC5, SC6, and SC8) isolated from milk from cows and goats and the biofilm formation on equipment. To evaluate the effectiveness of the formulation, studies were carried out through in situ applications of the Sf hydrogel as post-dipping in lactating cows and goats. Antibiogram tests showed the resistance of Staphylococcus aureus isolates to ampicillin, trimethoprim, and tetracycline. In the in vitro assays in bovine milk, the PDTa reduced the P. fluorescens (PV1) counts by 17.4% (p<0.05). In goat milk, the PDTa reduced the growth of S. aureus by up to 24.43% (SC8) (p<0.05), and for P. fluorescens (PC3), the inactivation was 50.25%. In biofilm formation, there were reduction of 66.66% (SV1) and 38.27% (SC5) in the adhesion of S. aureus to stainless steel coupons. For in situ applications, photoactivated Sf maintained bacterial counts in bovine milk similar to the control treatment (lactic acid). During the experimental period (28 days), there were reductions of 23.23% and 28.85% in staphylococci and Pseudomonas spp. in cow's milk and 76.13% for Pseudomonas spp. in goat milk (p<0.05). There was no significant difference in goat milk's somatic cell count (CCS). These results indicate that photoactivated Sf can help reduce milk contamination and maintain the health of the mammary gland.