Biodiversity losses are a major driver of global changes in ecosystem functioning. While most studies of the relationship between biodiversity and ecosystem functioning have examined randomized species losses, trait-based filtering associated with species-specific vulnerability to drivers of diversity loss can strongly influence how ecosystem functioning responds to declining biodiversity. Moreover, the responses of ecosystem functioning to diversity loss may be mediated by environmental variability interacting with the suite of traits remaining in depauperate communities. We do not yet understand how communities resulting from realistic diversity losses (filtered by response traits) influence ecosystem functioning (via effect traits of the remaining community), especially under variable environmental conditions. Here we directly test how realistic and randomized plant diversity losses influence productivity and invasion resistance across multiple years in a California grassland. Compared with communities based on randomized diversity losses, communities resulting from realistic (drought-driven) species losses had higher invasion resistance under climatic conditions that matched the trait-based filtering they experienced. However, productivity declined more with realistic than with randomized species losses across all years, regardless of climatic conditions. Functional response traits aligned with effect traits for productivity but not for invasion resistance. Our findings illustrate that the effects of biodiversity losses depend not only on the identities of lost species, but also on how the traits of remaining species interact with varying environmental conditions. Understanding the consequences of biodiversity change requires studies that evaluate trait-mediated effects of species losses and incorporate the increasingly variable climatic conditions that future communities are expected to experience.