Safeguarding river ecosystems is a precondition for attaining the UN Sustainable Development Goals (SDGs) related to water and the environment, while rigid implementation of such policies may hamper achievement of food security. River ecosystems provide life-supporting functions that depend on maintaining environmental flow requirements (EFRs). Here we establish gridded process-based estimates of EFRs and their violation through human water withdrawals. Results indicate that 41% of current global irrigation water use (997 km 3 per year) occurs at the expense of EFRs. If these volumes were to be reallocated to the ecosystems, half of globally irrigated cropland would face production losses of ≥10%, with losses of ∼20-30% of total country production especially in Central and South Asia. However, we explicitly show that improvement of irrigation practices can widely compensate for such losses on a sustainable basis. Integration with rainwater management can even achieve a 10% global net gain. Such management interventions are highlighted to act as a pivotal target in supporting the implementation of the ambitious and seemingly conflicting SDG agenda.