The virulence mechanisms that allow pathogens to colonize the intestine remain unclear. Here, we show that germ-free animals are unable to eradicate Citrobacter rodentium, a model for human infections with attaching and effacing bacteria. Early in infection, virulence genes were expressed and required for pathogen growth in conventionally raised mice but not germ-free mice. Virulence gene expression was down-regulated during the late phase of infection, which led to relocation of the pathogen to the intestinal lumen where it was outcompeted by commensals. The ability of commensals to outcompete C. rodentium was determined, at least in part, by the capacity of the pathogen and commensals to grow on structurally similar carbohydrates. Thus, pathogen colonization is controlled by bacterial virulence and through competition with metabolically related commensals.