There is growing interest in introducing ecological risks (ERs) and ecosystem services (ESs) into environmental policies and practices. However, the integration of ESs and ERs into actual decision-making remains insufficient. We simulated the spatiotemporal dynamics of ESs (e.g., carbon storage, water yield, habitat quality, and soil conservation) and ERs in the upper reach of the Yellow River (URYR) from 2000 to 2100. Additionally, we explored their relationships by combining the InVEST model and a landscape ecological risk model with CMIP6 data. Our main findings showed that regional ERs change in response to land use and environmental dynamics. Specifically, the ER area decreased by 27,673 m2 during 2000-2020, but it is projected to increase by 13,273, 438, and 68 m2 under the SSP1-2.6, SSP2-4.5, and SSP5-8.5 scenarios, respectively. We also observed remarkable spatial differences in ESs and ERs between past and future scenarios. For instance, the source area of the URYR exhibited high ESs and low ERs (P<0.001), while the ESs and ERs are declining and increasing, respectively, in the northeastern URYR (P<0.05). Finally, we proposed a spatial optimization framework to improve ESs and reduce ERs, which will support regional sustainable development.