As a critical ecological barrier, the upper Yangtze River (UYR) holds strategic importance for national ecological security. Understanding its habitat quality dynamics is essential for evaluating conservation efforts. However, there is a relative lack of long-term monitoring studies on habitat quality in this region, and the influencing factors remain insufficiently explored. Using the InVEST model, this study quantified the spatiotemporal evolution of habitat quality in the UYR from 1990 to 2020. Spatial autocorrelation analysis revealed distinct clustering patterns, and spatial regression models identified driving mechanisms. Results showed that habitat quality experienced a sharp decline (1990-2000), especially in the Jinsha River basin, followed by recovery due to the Natural Forest Protection (1998) and Grain-for-Green (2000) programs. High-quality areas clustered in the upper Jinsha and Min-Tuo basins, while low-quality areas were concentrated in urbanized regions of the Sichuan Basin and Jialing River basin. Elevation and slope indirectly improved habitat quality by promoting vegetation, whereas temperature, PM2.5, population density, and GDP had negative effects. Although ecological policies alleviated pressures, urbanized areas require further restoration. This study provides critical insights into conservation policy effectiveness and supports zonal ecological management in the UYR.