Bacterial pathogens such as Salmonella enterica serovar Typhimurium can resist phagocytosis by macrophages. Here we explored the role of bacterial heme biosynthesis in phagocytosis resistance. Using transposon sequencing (Tn-seq) during Salmonella infection of macrophages, we identify a methyltransferase, SirM, that indirectly inhibits phagocytosis of bacteria. Mechanistically, sirM is activated upon interaction with macrophages and methylates HemL, a key enzyme in heme biosynthesis, resulting in upregulation of heme synthesis by Salmonella. Salmonella-derived heme inhibits Cdc42 activation in a Toll-like receptor 4 (TLR4)-dependent manner to inhibit phagocytosis. Moreover, sirM promotes macrophage death by increasing heme synthesis. Experiments in mouse models show that sirM is required for virulence and confers a competitive advantage over intestinal commensal bacteria during infection. We also found that sirM is distributed among enteric pathogens. Collectively, our findings show that bacterial heme promotes evasion of phagocyte responses and pathogenesis to confer an advantage in the host.