High temperature negatively impacts the yield and quality of fruit crops. Exogenous melatonin (MT) application has shown the capability to enhance heat tolerance, but the response of endogenous MT to heat stress, particularly in perennial fruit trees, remains elusive. This study investigated the effects of high temperatures on transgenic apple plants overexpressing the MT biosynthetic gene N-acetylserotonin methyltransferase 9 ( MdASMT9). Endogenous MT protected transgenic plants from heat stress, scavenging reactive oxygen species (ROS) and increasing soluble carbohydrates and amino acids levels. MdASMT9-overexpressing plants also maintained higher photosynthetic activity by protecting the chloroplasts from damage. Transcriptome sequencing indicates that MdASMT9 overexpression promoting the expression of HSFA1d, HSFA2-like, and HSFA9b, and inhibiting the transcription of HSFB1 and HSFB2b. Application of MT and overexpression of MdASMT9 reduced abscisic acid (ABA) accumulation through promoting MdWRKY33-mediated transcriptional inhibition of MdNCED1 and MdNCED3, thus promoting stomatal opening for better heat dissipation. Furthermore, melatonin enhanced autophagic activity through promoting MdWRKY33-mediated transcriptional enhancement of MdATG18a under heat stress . These findings provide new sight into the regulation of endogenous MT and its role in improving heat tolerance in perennial fruit trees.