Straw as an important sustainable agricultural resource and its interaction with nitrogen (N) fertiliser may affect soil carbon sink and food security. Here, machine learning based on meta-analysis was conducted to assess the effect of straw and N input on soil organic carbon (SOC) and crop yield by compiling worldwide site-specific studies and high-resolution databases. The results highlight that the effects of straw return depend on management, climate, and soil properties. Meta-analysis results revealed that returning 8000–11,000 kg ha−1straw can achieve greater benefits. Moreover, the model forecasts demonstrate that optimizing straw and N input could increase surface SOC storage by 12 % (20.4 Pg) and global crop yield by 19.7 % (308 Tg). According to the optimization model, SOC storage and crop yield could further increase by 12.9 % (22.8 Pg) and 15.7 % (236.9 Tg) respectively by 2041–2060. These insights underscore the importance of optimizing straw and N input for sustainable agriculture under climate change.