Chemotactic migration of bacteria—their ability to direct multicellular motion along chemical gradients—is central to processes in agriculture, the environment, and medicine. However, studies are typically performed in bulk liquid, despite the fact that most bacteria inhabit heterogeneous porous media such as soils, sediments, and biological gels. Here, we directly visualize the migration of E. coli populations in 3D porous media. We find that pore-scale confinement is a strong regulator of chemotactic migration. Strikingly, cells use a different primary mechanism to direct their motion in confinement than in bulk liquid. Further, confinement markedly alters the dynamics and morphology of the migrating population—features that can be described by a continuum model, but only when standard motility parameters are substantially altered from their bulk liquid values. Our work thus provides a framework to predict and control the migration of bacteria, and active matter in general, in heterogeneous environments.