The role of biodiversity in mediating ecosystem processes has been the subject of focused theoretical and empirical attention since the mid-1990s. Theory predicts that the balance between species richness and identity effects will critically depend on the degree of environmental heterogeneity, which dictates the extent to which differences between species in patterns of resource use can be expressed. We conducted a mesocosm experiment to explicitly test this hypothesis. We manipulated the richness and identity of intertidal molluscan grazers, as well as the spatial heterogeneity of the substrate upon which they grazed. The magnitude of algal consumption was used as our focal ecosystem process. The grazer treatments consisted of three monocultures and a single polyculture including all three species; heterogeneity was represented as the proportion of topographically complex and flat substrate. Species identity had strong effects on homogeneous substrates, with the identity of the best-performing species dependent on the substrate. On the heterogeneous substrate, suitable conditions for all three species were represented, allowing the expression of spatial complementarity of resource use and the enhancement of total algal consumption. Our findings provide the first explicit experimental evidence that spatial heterogeneity of the physical environment can play a key role in mediating effects of species diversity.