Melatonin (MT) is an important regulator that participates in plant growth and stress tolerance. The aim of this study was to determine how MT alleviates the decline of photosynthesis in cucumber seedlings under high-temperature stress. The results showed that foliar spraying of MT significantly alleviates the heat symptoms of cucumber by reducing the electrolyte leakage (EL) and increasing the net photosynthetic rate (Pn), light saturation CO2 assimilation rate (Asat), actual photochemical efficiency under light (Phi PSII),and maximum photochemical efficiency of photosystem II under dark (Fv/Fm). The mitigative effect of MT depended on the concentration and 100 mu mol<middle dot>L-1 MT was the optimal concentration. Moreover, we found that overexpression of N-acetyl-5-serotonin-methyltransferase (ASMT) significantly increased endogenous MT content and heat tolerance of cucumber. Furthermore, compared to WT, OE- CsASMT plants displayed higher Pn, A sat and the activities and relative expression of photosynthetic enzymes under high-temperature stress. Meanwhile, overexpression of CsASMT significantly alleviated the damage of the PSII donor side and acceptor side and the degradation of D1 and PsaD protein under heat stress, thereby reducing the photoinhibition of PSI and PSII and enhancing the photosynthetic capacity of cucumber. While, suppression of CsASMT aggravated the damage of photosynthetic apparatus. Furthermore, the suppression of proton gradient regulation 5 (PGR5) aggravated the decline of photosynthesis caused by heat stress, which could not be reversed with the application of MT. Specifically, MT alleviated photoinhibition caused by heat stress via regulating PGR5 depended-CEF. Taken together, our results help to reveal the regulation mechanism of MT on photosynthesis in cucumber under heat stress.