An antibacterial compound, pyrrole-2-carboxylic acid (PCA), was isolated from an endophyte named Bacillus cereus ZBE in this study. RNA sequencing identified 14 genes encoding 9 key enzymes involved in PCA biosynthesis in B. cereus ZBE. The PCA production was enhanced 21-fold (149.63 mg/L) by optimization with the Plackett−Burman design and the response surface methodology. The optimum fermentation conditions were found to be 0.5% glycerinum, 1% peptone, 25% loaded liquid, initial pH at 7.0, inoculum size of 4%, incubation temperature at 37.72 °C, rotating speed of 120 rpm, and incubation for 48 h. In addition, PCA showed broad-spectrum antibacterial properties against a variety of foodborne pathogens. A further mechanism study demonstrated that PCA might exhibit antibacterial activity by inducing severe membrane damage in bacterial cells with a loss of membrane integrity. These findings suggested that PCA might be a promising source of natural antibacterial compounds used as preservatives in the food industry.