The upper reaches of the Tarim River are a typical arid and fragile ecosystem. Plant diversity and community stability play an important role in ecosystem balance and sustainable development. We explored species diversity and community stability in different habitats (riverbank, transition zone, and desert margin) in the upper reaches of the Tarim River Basin, as well as the influencing factors. The results showed that
Phragmites australis,
Populus euphratica, and
Halogeton arachnoideus were the dominant species in the habitats of riverbank, transition zone, and desert margin, respectively. Along the riverbank-transition zone-desert margin, species diversity increased first and then decreased. The community stability in different habitats was manifested as follows: desert margin > transition zone > riverbank. The results of PCA showed that species diversity was positively correlated with soil organic matter and was negatively correlated with groundwater depth, soil pH, and total salt content. Structural equation modeling revealed that total salt content and species diversity were negatively correlated with community stability. These results provide a theoretical basis for further research on ecosystem stability and sustainability in the upper reaches of the Tarim River.