Metabolomics provides an unprecedented window into diverse plant secondary metabolites that represent a potentially critical niche dimension in tropical forests underlying species coexistence. Here, we used untargeted metabolomics to evaluate chemical composition of 358 tree species and its relationship with phylogeny and variation in light environment, soil nutrients, and insect herbivore leaf damage in a tropical rainforest plot. We report no phylogenetic signal in most compound classes, indicating rapid diversification in tree metabolomes. We found that locally co-occurring species were more chemically dissimilar than random and that local chemical dispersion and metabolite diversity were associated with lower herbivory, especially that of specialist insect herbivores. Our results highlight the role of secondary metabolites in mediating plant-herbivore interactions and their potential to facilitate niche differentiation in a manner that contributes to species coexistence. Furthermore, our findings suggest that specialist herbivore pressure is an important mechanism promoting phytochemical diversity in tropical forests.