Optimizing urban morphology effectively mitigates urban heat island effects. However, previous research on urban morphology and land surface temperature (LST) has often concentrated on entire cities or specific local areas, neglecting the heterogeneity within urban regions. This study investigates the impact of two-dimensional (2D) and three-dimensional (3D) urban morphology on LST based on urban-rural gradients. Firstly, we calculated nine 2D and 3D indicators to comprehensively depict the urban morphology. Then, we employed a multi-iterative quantile method based on nighttime light data to delineate three city subclasses: urban core, suburb, and rural area (USR). Finally, we quantified the impact of these indicators on LST thorough correlation analysis and a random forest (RF) model. Results indicate that, overall and post-USR classification, the sum of building area (SBA) is the primary factor influencing LST, contributing up to 31.6% in suburb. The main 3D factors affecting LST differ across subclasses: in rural area, it is the sum of building surface (SBS, 12.9%); in suburb, it is the spatial congestion degree (SCD, 9.7%); and in urban cores, it is the mean building height (MBH, 12.0%). Notably, the influence of 3D indicators increases from 68.1% in rural area to 72.3% in urban core. In urban core, MBH and standard deviation of height (SDH) are negatively correlated with LST. Case studies in Tianhe District (Guangzhou) and Futian District (Shenzhen) confirmed these indicators do have a certain effect on reducing the temperature. This study provides valuable insights for improving the urban thermal environment and promoting sustainable urban development.