Soybean (Glycine max (L.) Merr.) is an important crop that provides a sustainable source of protein and oil worldwide. Soybean cyst nematode (Heterodera glycines Ichinohe) is a microscopic roundworm that feeds on the roots of soybean and is a major constraint to soybean production. This nematode causes more than US$1 billion in yield losses annually in the United States alone, making it the most economically important pathogen on soybean. Although planting of resistant cultivars forms the core management strategy for this pathogen, nothing is known about the nature of resistance. Moreover, the increase in virulent populations of this parasite on most known resistance sources necessitates the development of novel approaches for control. Here we report the map-based cloning of a gene at the Rhg4 (for resistance to Heterodera glycines 4) locus, a major quantitative trait locus contributing to resistance to this pathogen. Mutation analysis, gene silencing and transgenic complementation confirm that the gene confers resistance. The gene encodes a serine hydroxymethyltransferase, an enzyme that is ubiquitous in nature and structurally conserved across kingdoms. The enzyme is responsible for interconversion of serine and glycine and is essential for cellular one-carbon metabolism. Alleles of Rhg4 conferring resistance or susceptibility differ by two genetic polymorphisms that alter a key regulatory property of the enzyme. Our discovery reveals an unprecedented plant resistance mechanism against a pathogen. The mechanistic knowledge of the resistance gene can be readily exploited to improve nematode resistance of soybean, an increasingly important global crop.