Digital elevation models (DEMs) are widely used in digital terrain analysis, global change research, digital Earth applications, and studies concerning natural disasters. In this investigation, a thorough examination and comparison of five open-source DEMs (ALOS PALSAR, SRTM1 DEM, SRTM3 DEM, NASADEM, and ASTER GDEM V3) was carried out, with a focus on the Chongqing region as a specific case study. By utilizing ICESat-2 ATL08 data for validation and employing a random forest model to refine terrain variables such as slope, aspect, land cover, and landform type, a study was undertaken to assess the precision of DEM data. Research indicates that spatial resolution significantly impacts the accuracy of DEMs. ALOS PALSAR demonstrated satisfactory performance, reducing the corrected root mean square error (RMSE) from 13.29 m to 9.15 m. The implementation of the random forest model resulted in a significant improvement in the accuracy of the 30 m resolution NASADEM product. This improvement was supported by a decrease in the RMSE from 38.24 m to 9.77 m, demonstrating a significant 74.45% enhancement in accuracy. Consequently, the ALOS PALSAR and NASADEM datasets are considered the preferred data sources for mountainous urban areas. Furthermore, the study established a clear relationship between the precision of DEMs and slope, demonstrating a consistent decline in precision as slope steepness increases. The influence of aspect on accuracy was considered to be relatively minor, while vegetated areas and medium-to-high-relief mountainous terrains were identified as the main challenges in attaining accuracy in the DEMs. This study offers valuable insights into selecting DEM datasets for complex terrains in mountainous urban areas, highlighting the critical importance of choosing the appropriate DEM data for scientific research.