Anthocyanins are plant pigments known for their radical scavenging activity. However, the current understanding of the effects of anthocyanins in bacterial infection is limited to crude extracts. Additionally, most studies about cyanidin-3-glucoside (C3G), an anthocyanin compound from the cyanidin class, were limited to in vitro experiments. This paper investigated the protective mechanism of C3G against selected pathogens, namely Staphylococcus aureus (S. aureus), Enterococcus faecalis (E. faecalis), Klebsiella pneumoniae (K. pneumoniae), and Proteus mirabilis (P. mirabilis) using Caenorhabditis elegans (C. elegans) as the infection model. The nematodes were supplemented with varying sublethal concentrations of C3G every day after hatching. Besides, the concentrations of C3G used exhibit no bacterial growth suppression against the pathogens. The nematodes transferred to different plates were flooded with varying bacteria. The number of surviving worms were counted every day until all worms were deceased. To hypothesize the protective mechanism of C3G, its 3D structure was docked in the crystal structures of the different proteins produced by each pathogen. These protein molecules represent their virulence factors, which are available in the Protein Data Bank. The docked crystal structures were evaluated for their binding energies and binding interactions. Results show that C3G rescues C. elegans against S. aureus but not from E. faecalis, despite both are gram-positive. This observation is similar to the gram-negative pathogens where C. elegans were protected from P. mirabilis treatment but not against K. pneumoniae. Consistently, the docked crystal structures of C3G reveal to have a high binding affinity with amidohydrolase and exfoliative toxin A, which are virulence factors of P. mirabilis and S. aureus, respectively. These findings suggest that the protective mechanism of C3G against pathogens may influence the virulence factors of certain bacteria only.