Decades of research on the infamous antinutritional steroidal glycoalkaloids (SGAs) in Solanaceae plants have provided deep insights into their metabolism and roles. However, engineering SGAs in heterologous hosts has remained a challenge. We discovered that a protein evolved from the machinery involved in building plant cell walls is the crucial link in the biosynthesis of SGAs. We show that cellulose synthase-like M [GLYCOALKALOID METABOLISM15 (GAME15)] functions both as a cholesterol glucuronosyltransferase and a scaffold protein. Silencing GAME15 depletes SGAs, which makes plants more vulnerable to pests. Our findings illuminate plant evolutionary adaptations that balance chemical defense and self-toxicity and open possibilities for producing steroidal compounds in heterologous systems for food, cosmetics, and pharmaceuticals.