Tomato (Solanum lycopersicum L.) is rich in nutrients and has been an important target for enhancing the accumulation of various metabolites. Tomato also contains cholesterol-derived molecules, steroidal glycoalkaloids (SGAs), which contribute to pathogen defense but are toxic to humans and considered antinutritional compounds. Previous studies suggest the role of various transcription factors in SGA biosynthesis; however, the role of light and associated regulatory factors has not been studied in tomatoes. Here, we demonstrated that SGA biosynthesis is regulated by light through the ELONGATED HYPOCOTYL 5 homolog, SlHY5, by binding to light-responsive G-boxes present in the promoters of structural and regulatory genes. SlHY5 complemented Arabidopsis (Arabidopsis thaliana) and tobacco (Nicotiana tabacum) hy5 mutants at molecular, morphological, and biochemical levels. CRISPR/Cas9-based knockout tomato plants, SlHY5CR, showed downregulation of SGA and phenylpropanoid pathway genes, leading to a significant reduction in SGA (α-tomatine and dehydrotomatine) and flavonol contents, whereas plants overexpressing SlHY5 (SlHY5OX) showed the opposite effect. Enhanced SGA and flavonol levels in SlHY5OX lines provided tolerance against Alternaria solani fungus, while SlHY5CR lines were susceptible to the pathogen. This study advances our understanding of the HY5-dependent light-regulated biosynthesis of SGAs and flavonoids and their role in biotic stress in tomatoes.