Accurately mapping the spatial patterns of soil organic carbon (SOC) in the middle section of Tianshan Mountains, Xinjiang, is essential for evaluating soil quality, enhancing carbon sequestration, and ensuring ecological security. However, significant variations in terrain, precipitation, evaporation, vegetation cover, and soil pH, particularly between areas close to and distant from the mountains, result in complex ecological conditions. This complexity leads to high spatial heterogeneity in regional SOC, creating substantial challenges for precise SOC mapping using digital soil mapping techniques. To address this, this study utilized 463 soil samples and applied multiple machine learning models, including eXtreme gradient boosting (XGBoost, XGB), to generate a spatial distribution map of SOC. In addition, the Shapley Additive exPlanations (SHAP) algorithm was employed to identify the primary factors influencing SOC spatial variation. Results indicated that the XGB model outperformed others, achieving a fitting R2 of 0.716, a liquid chromatography at critical conditions of 0.824, and a root mean square error of 1.554 g·kg-1. The spatial distribution of SOC exhibited higher values in the northern region and lower values in the southern. Further SHAP analysis showed that SOC content is primarily affected by soil pH, elevation, and mean annual precipitation. Partial dependence plots identified threshold effects in the relationships between environmental variables and SOC. Notably, SOC content declined sharply when pH exceeded 7.8, mean annual evaporation surpassed 620 mm, mean annual precipitation fell below 300 mm, or net primary productivity dropped below 130 g C·m-2·a-1. These findings suggest that managing soil pH, evapotranspiration, and vegetation growth is beneficial for regional soil carbon sequestration. Implementing strategies such as applying acid amendments, organic fertilizers, and ensuring agricultural irrigation can help regulate the key variables affecting SOC and increase SOC content. This study reinforces the importance of considering factors such as soil pH, elevation, and mean annual precipitation. The results provide valuable data support for soil carbon sink management in the middle section of Tianshan Mountains and serve as a significant reference for digital SOC mapping in other arid and semi-arid regions.