Accelerating rates of species extinctions and disease emergence underscore the importance of understanding how changes in biodiversity affect disease outcomes1,2,3. Over the past decade, a growing number of studies have reported negative correlations between host biodiversity and disease risk4,5,6,7,8, prompting suggestions that biodiversity conservation could promote human and wildlife health9,10. Yet the generality of the diversity–disease linkage remains conjectural11,12,13, in part because empirical evidence of a relationship between host competence (the ability to maintain and transmit infections) and the order in which communities assemble has proven elusive. Here we integrate high-resolution field data with multi-scale experiments to show that host diversity inhibits transmission of the virulent pathogen Ribeiroia ondatrae and reduces amphibian disease as a result of consistent linkages among species richness, host composition and community competence. Surveys of 345 wetlands indicated that community composition changed nonrandomly with species richness, such that highly competent hosts dominated in species-poor assemblages whereas more resistant species became progressively more common in diverse assemblages. As a result, amphibian species richness strongly moderated pathogen transmission and disease pathology among 24,215 examined hosts, with a 78.4% decline in realized transmission in richer assemblages. Laboratory and mesocosm manipulations revealed an approximately 50% decrease in pathogen transmission and host pathology across a realistic diversity gradient while controlling for host density, helping to establish mechanisms underlying the diversity–disease relationship and their consequences for host fitness. By revealing a consistent link between species richness and community competence, these findings highlight the influence of biodiversity on infection risk and emphasize the benefit of a community-based approach to understanding infectious diseases.