The relationship between biodiversity and ecosystem functioning (BEF) has become a cornerstone of community and ecosystem ecology and an essential criterion for making decisions in conservation biology and policy planning. It has recently been proposed that evolutionary history should influence the BEF relationship because it determines species traits and, thus, species’ ability to exploit resources. Here we test this hypothesis by combining experimental evolution with a BEF experiment. We isolated 20 bacterial strains from a marine environment and evolved each to be generalists or specialists. We then tested the effect of evolutionary history on the strength of the BEF relationship with assemblages of 1 to 20 species constructed from the specialists, generalists and ancestors. Assemblages of generalists were more productive on average because of their superior ability to exploit the environmental heterogeneity. The slope of the BEF relationship was, however, stronger for the specialist assemblages because of enhanced niche complementarity. These results show how the BEF relationship depends critically on the legacy of past evolutionary events.