Steroidal glycoalkaloids (SGAs) are specialized metabolites produced by hundreds of Solanum species including food crops, such as tomato, potato and eggplant. Unlike true alkaloids, nitrogen is introduced at a late stage of SGA biosynthesis through an unknown transamination reaction. Here, we reveal the mechanism by which GLYCOALKALOID METABOLISM12 (GAME12) directs the biosynthesis of nitrogen-containing steroidal alkaloid aglycone in Solanum. We report that GAME12, a neofunctionalized γ-aminobutyric acid (GABA) transaminase, undergoes changes in both active site specificity and subcellular localization to switch from its renown and generic activity in core metabolism to function in a specialized metabolic pathway. Moreover, overexpression of GAME12 alone in engineered S. nigrum leaves is sufficient for de novo production of nitrogen-containing SGAs. Our results highlight how hijacking a core metabolism GABA shunt enzyme is crucial in numerous Solanum species for incorporating a nitrogen to a steroidal-specialized metabolite backbone and form defensive alkaloids.