The Asian green revolution trebled grain yields through agrochemical intensification of monocultures. Associated environmental costs have subsequently emerged. A rapidly changing world necessitates sustainability principles be developed to reinvent these technologies and test them at scale. The need is particularly urgent in Africa, where ecosystems are degrading and crop yields have stagnated. An unprecedented opportunity to reverse this trend is unfolding in Malawi, where a 90% subsidy has ensured access to fertilization and improved maize seed, with substantive gains in productivity for millions of farmers. To test if economic and ecological sustainability could be improved, we preformed manipulative experimentation with crop diversity in a countrywide trial (n = 991) and at adaptive, local scales through a decade of participatory research (n = 146). Spatial and temporal treatments compared monoculture maize with legume-diversified maize that included annual and semiperennial (SP) growth habits in temporal and spatial combinations, including rotation, SP rotation, intercrop, and SP intercrop systems. Modest fertilizer intensification doubled grain yield compared with monoculture maize. Biodiversity improved ecosystem function further: SP rotation systems at half-fertilizer rates produced equivalent quantities of grain, on a more stable basis (yield variability reduced from 22% to 13%) compared with monoculture. Across sites, profitability and farmer preference matched: SP rotations provided twofold superior returns, whereas diversification of maize with annual legumes provided more modest returns. In this study, we provide evidence that in Africa, crop diversification can be effective at a countrywide scale, and that shrubby, grain legumes can enhance environmental and food security.ecosystem services | nitrogen | rural development | sustainable agriculture