Climate change and biodiversity erosion are two major threats to the vitality of the world's forests. However, it is difficult to predict the extent to which tree diversity and environmental conditions interact to modify forest health, and in particular resistance and/or tolerance to insect pests. We used a tree diversity experiment with an irrigation treatment to investigate the effect of mixing and diluting host pines (Pinus pinaster) amongst broadleaved trees on pine stem borer (Dioryctria sylvestrella) infestations under contrasting drought conditions. We further tested whether the attack patterns of this primary pest resulted from direct effects of tree diversity and drought, or was indirectly mediated by their combined effects on pine vigor. The total number of stem borer attacks per plot significantly decreased with tree species richness, i.e., increased with the density of pines, being maximum in pure plots. There were more attacks in irrigated plots. Mixing pines with birches resulted in lower plot infestations but only in irrigated plots. The probability of individual tree being attacked was higher in irrigated plots and decreased with increasing pine density. More vigorous trees, i.e., with higher radial growth, were more likely to be attacked. We suggest that the pine stem borer is attracted by the volatile organic compounds released by the resin exuding from bark cracks. Bark fissuring increases with radial growth, which is enhanced by irrigation and reduced intraspecific competition in low-density pine plots. The presence of birch limits plot infestation, probably because it disrupts host-finding behavior through repellence by non-host volatiles. This phenomenon is mainly observed when pines are vigorous, i.e., when they are irrigated, and particularly attractive to the stem borer. Our results confirm that more severe droughts decrease the attacks by primary pests feeding on tree trunks, by reducing host tree vigor, and that focal tree species can obtain protection against specialized insect pests when mixed with non-host species. The functional characteristics of herbivorous insects are therefore to be taken into account in predicting the interactive effects of climate change and loss of diversity on forest health.