The endophytic fungi of certain grasses and other herbaceous plants have long been known to provide plants with anti-herbivore defense compounds, but there is little information about whether the endophytes of trees also engage in such mutualisms. We investigated the influence of the endophytic fungus Cladosporium cladosporioides on the chemical defenses of black poplar (Populus nigra) trees and the consequences for feeding preference and fitness of herbivorous insects and insect community assembly. Endophyte colonization increased both constitutive- and induced poplar defenses. Generalist Lymantria dispar larvae preferred and performed better on uninfected over endophyte-infected poplar leaves, most likely due to higher concentrations of salicinoids in endophytic leaves and the endophyte-produced alkaloid stachydrine. Under field conditions, the endophytic fungus also shapes insect community assembly in young black poplar trees. Our results show that endophytic fungi can play a major role both in defending trees against herbivorous insects and in structuring insect communities.