Numerous gram-negative bacterial pathogens employ the type III secretion system (T3SS), a multiprotein injectisome, to deliver virulence proteins into host cells and cause diseases. We uncover erucamide as a previously unknown phytoalexin of both dicots and monocots that blocks the T3SS function of multiple bacterial pathogens. Genetically impairing erucamide accumulation or exogenous application in Arabidopsis highlighted erucamide’s role in antibacterial immunity. Erucamide binds Hypersensitive response and conserved C (HrcC), a key T3SS component, to block injectisome assembly. Analyses of erucamide analogs and HrcC mutants indicated that the erucamide-HrcC binding is required for inhibiting T3SS in vitro and antibacterial resistance in plants, suggesting an essential role of erucamide-HrcC binding in disease resistance. This work reveals a plant chemical defense that targets major virulence machinery in bacterial pathogens.