Positive relationship between biodiversity and ecosystem functioning has been observed in many studies, but how this relationship is affected by environmental stress is largely unknown. To explore this influence, we measured the biomass of microalgae grown in microcosms along two stress gradients, heat and salinity, and compared our results with 13 published case studies that measured biodiversity–ecosystem functioning relationships under varying environmental conditions. We found that positive effects of biodiversity on ecosystem functioning decreased with increasing stress intensity in absolute terms. However, in relative terms, increasing stress had a stronger negative effect on low-diversity communities. This shows that more diverse biotic communities are functionally less susceptible to environmental stress, emphasises the need to maintain high levels of biodiversity as an insurance against impacts of changing environmental conditions and sets the stage for exploring the mechanisms underlying biodiversity effects in stressed ecosystems.