Abstract ASMT/COMT, as a key rate-limiting enzyme regulating melatonin biosynthesis, has garnered significant attention. This study investigates the evolutionary mechanisms of the ASMT/COMT gene family in melatonin biosynthesis. A total of 28 010 ASMT/COMT genes from 1052 species were identified through an integrated approach combining large-scale identifications and analyses. At the pan-genome level, we identified 5186, 336, 2137 and 1814 ASMT/COMT genes respectively in Triticum aestivum, Aegilops tauschii, diploid and tetraploid Solanum tuberosum haplotype genomes (247, 86, 670 and 96 orthologous gene groups). Expansion patterns of the ASMT/COMT gene family were explored through synteny networks in 104 Poaceae and 88 Solanaceae plants. Further investigation of copy number variation (CNV) in the 1052 species, along with a focused analysis of hexaploid wheat and its diploid progenitor Ae. tauschii, indicated a functional divergence linked to gene dosage. The catalytically efficient COMT is maintained at low-copy conditions, whereas the less active ASMT is amplified under high-copy conditions. Intriguingly, in polyploid potatoes, the total ASMT/COMT copy number was lower in tetraploids than in diploids, suggesting a distinct dosage balance mechanism operating in polyploids. In contrast, the melatonin receptor CAND2 consistently remained in a low-copy state, with no significant correlation to ASMT/COMT copy number. Expression analysis revealed that COMT is generally expressed at higher levels than ASMT, highlighting a compensatory relationship between gene dosage and transcriptional regulation. Collectively, our findings uncover a dosage-balance mechanism that fine-tunes melatonin biosynthetic homeostasis through coordinated copy number variation and expression regulation, offering a new perspective on the evolution of metabolic enzymes.