Ergot alkaloids are toxins and important pharmaceuticals that are produced biotechnologically on an industrial scale. The first committed step of ergot alkaloid biosynthesis is catalyzed by dimethylallyl tryptophan synthase (DMATS; EC 126.96.36.199). Orthologs of DMATS are found in many fungal genomes. We report here the x-ray structure of DMATS, determined at a resolution of 1.76 A. A complex of DMATS from Aspergillus fumigatus with its aromatic substrate L-tryptophan and with an analogue of its isoprenoid substrate dimethylallyl diphosphate reveals the structural basis of this enzyme-catalyzed Friedel-Crafts reaction, which shows strict regiospecificity for position 4 of the indole nucleus of tryptophan as well as unusual independence of the presence of Mg(2+) ions. The 3D structure of DMATS belongs to a rare beta/alpha barrel fold, called prenyltransferase barrel, that was recently discovered in a small group of bacterial enzymes with no sequence similarity to DMATS. These bacterial enzymes catalyze the prenylation of aromatic substrates in the biosynthesis of secondary metabolites (i.e., a reaction similar to that of DMATS).