1. Species-rich communities exhibit higher levels of ecosystem functioning compared to species-poor ones, and this positive relationship strengthens over time. One proposed explanation for this phenomenon is the reduction of niche overlap among plants or animals, which corresponds to increased complementarity and reduced competition. 2. In order to examine the potential of increased complementarity among plants or animals to strengthen the relationship between diversity and ecosystem functions, we integrated models of bio-energetic population dynamics and food-web assembly. Through the simulation of various scenarios of plant and animal complementarity change, we sought to elucidate the mechanisms underlying the observed increases in (1) primary productivity, (2) control of herbivores by predators, and (3) reduction of herbivore pressure on plants in species-rich communities.3. Our findings reveal that increased niche complementarity of plants can steepen the diversity-function relationships if it does not increase their intraspecific competition, while increasing complementarity among animals during community assembly can also have a positive effect but with considerable variability. 4. The study highlights the importance of trait variation both among and within species, and the interplay between intra- and interspecific competition strength in shaping the functioning of ecosystems over time. These results offer insights into the mechanisms underpinning the diversity-functioning relationship, and have practical implications for ecosystem management and conservation efforts.