Tropical forests are important reservoirs of biodiversity, but the processes that maintain this diversity remain poorly understood. The Janzen–Connell hypothesis suggests that specialized natural enemies such as insect herbivores and fungal pathogens maintain high diversity by elevating mortality when plant species occur at high density (negative density dependence; NDD). NDD has been detected widely in tropical forests, but the prediction that NDD caused by insects and pathogens has a community-wide role in maintaining tropical plant diversity remains untested. We show experimentally that changes in plant diversity and species composition are caused by fungal pathogens and insect herbivores. Effective plant species richness increased across the seed-to-seedling transition, corresponding to large changes in species composition5. Treating seeds and young seedlings with fungicides significantly reduced the diversity of the seedling assemblage, consistent with the Janzen–Connell hypothesis. Although suppressing insect herbivores using insecticides did not alter species diversity, it greatly increased seedling recruitment and caused a marked shift in seedling species composition. Overall, seedling recruitment was significantly reduced at high conspecific seed densities and this NDD was greatest for the species that were most abundant as seeds. Suppressing fungi reduced the negative effects of density on recruitment, confirming that the diversity-enhancing effect of fungi is mediated by NDD. Our study provides an overall test of the Janzen–Connell hypothesis and demonstrates the crucial role that insects and pathogens have both in structuring tropical plant communities and in maintaining their remarkable diversity.