Pericyclic reactions-which proceed in a concerted fashion through a cyclic transition state-are among the most powerful synthetic transformations used to make multiple regioselective and stereoselective carbon-carbon bonds. They have been widely applied to the synthesis of biologically active complex natural products containing contiguous stereogenic carbon centres. Despite the prominence of pericyclic reactions in total synthesis, only three naturally existing enzymatic examples (the intramolecular Diels-Alder reaction, and the Cope and the Claisen rearrangements) have been characterized. Here we report a versatile S-adenosyl-l-methionine (SAM)-dependent enzyme, LepI, that can catalyse stereoselective dehydration followed by three pericyclic transformations: intramolecular Diels-Alder and hetero-Diels-Alder reactions via a single ambimodal transition state, and a retro-Claisen rearrangement. Together, these transformations lead to the formation of the dihydropyran core of the fungal natural product, leporin. Combined in vitro enzymatic characterization and computational studies provide insight into how LepI regulates these bifurcating biosynthetic reaction pathways by using SAM as the cofactor. These pathways converge to the desired biosynthetic end product via the (SAM-dependent) retro-Claisen rearrangement catalysed by LepI. We expect that more pericyclic biosynthetic enzymatic transformations remain to be discovered in naturally occurring enzyme 'toolboxes'. The new role of the versatile cofactor SAM is likely to be found in other examples of enzyme catalysis.