Groundwater plays a crucial role in regulating plant growth in arid regions and has significant effects on plant physiological mechanisms. However, research on the influence of groundwater change on plant ecological stoichiometry is still limited. Therefore, this study was carried out to obtain the variations in assimilated branches and soil ecological stoichiometry of two dominant species in the Gurbantunggut Desert (Haloxylon ammodendron and Haloxylon persicum) at different groundwater depths to reveal the responses of desert plants to groundwater depth changes. The results showed that (1) H. persicum branches’ stress tolerance indicators (C:N, C:P) are higher, while nutritional indicators (N:P) are lower. The soil nutrient of H. ammodendron is richer. (2) The ecological stoichiometry varied significantly along the groundwater gradient. With the deepening of groundwater, the branches C, N and P increased, and the variation in element ratio was inconsistent. Most of the soil properties was inversely proportional to the depth of groundwater. (3) Groundwater depth was a vital environmental factor affecting the assimilated branches ecological stoichiometry. Soil properties also had a significant influence on element accumulation in assimilated branches. (4) Regulating the allocation of branches ecological stoichiometry is an adaptation of two Haloxylon species to cope with local hydrological conditions changes. These findings provide novel insights into desert plant responses to different groundwater conditions within fragile desert ecosystems and may have implications for the implementation of effective measures related to the stability and sustainability of desert ecosystems.