Species diversity influences the productivity of ecosystems across habitats, and may influence their susceptibility to environmental changes. More diverse communities are often found to be more productive because selection and complementarity effects allow more efficient use of available resources. However, which principles promote coexistence in pelagic model ecosystems is only beginning to be understood as are controls on the diversity–productivity relationship. Here we show that the diversity–productivity relationship of phytoplankton in a global self-assembling ocean ecosystem model depends on the simulated nutrient supply. Increasing productivity with increasing diversity can be found in regions with high nutrient supply. Using a simple idealized model we show that a more diverse community can be more productive if different phytoplankton types utilize complementary niches, here created by preferential zooplankton grazing, thereby increasing resource use. In our model context, total nutrient supply determines a maximum diversity sustained by the ecosystem. Systems with a low nutrient supply cannot sustain high productivity of more diverse communities and produce a neutral or even negative diversity–productivity relationship. Our model results suggest links between diversity, productivity and export production in marine pelagic ecosystems, with the potential for feedbacks of diversity on productivity in response to expected future environmental changes.