The intestinal mucosa is a particularly dynamic environment in which the host constantly interacts with trillions of commensal microorganisms, known as the microbiota, and periodically interacts with pathogens of diverse nature. In this Review, we discuss how mucosal immunity is controlled in response to enteric bacterial pathogens, with a focus on the species that cause morbidity and mortality in humans. We explain how the microbiota can shape the immune response to pathogenic bacteria, and we detail innate and adaptive immune mechanisms that drive protective immunity against these pathogens. The vast diversity of the microbiota, pathogens and immune responses encountered in the intestines precludes discussion of all of the relevant players in this Review. Instead, we aim to provide a representative overview of how the intestinal immune system responds to pathogenic bacteria.