Background: Folates are essential for life. Unlike mammals, most microorganisms must synthesize folates de novo. 6-Hydroxymethyl-7,8-dihydropterin pyrophosphokinase (HPPK) catalyzes pyrophosphoryl transfer from ATP to 6-hydroxymethyl-7,8-dihydropterin (HP), the first reaction in the folate pathway, and therefore is an ideal target for developing novel antimicrobial agents. HPPK from Escherichia coli is 158-residue thermostable protein that provides a convenient model system for mechanistic studies. Crystal structures have been reported for HPPK without bound ligand, containing an HP analog, and complexed with an HF analog, two Mg2+ ions, and ATP. Results: We present the 1.25 Angstrom crystal structure of HPPK in complex with HP, two Mg2+ ions, and AMPCPP (an ATP analog that inhibits the enzymatic reaction). This structure demonstrates that the enzyme seals the active center where the reaction occurs. The comparison with unligated HPPK reveals dramatic conformational changes of three flexible loops and many sidechains. The coordination of Mg2+ ions has been defined and the roles of 26 residues have been derived. Conclusions: HPPK-HP-MgAMPCPP mimics most closely the natural ternary complex of HPPK and provides details of protein-substrate interactions. The coordination of the two Mg2+ ions helps create the correct geometry for the one-step reaction of pyrophosphoryl transfer, for which we suggest an in-line single displacement mechanism with some associative character in the transition state. The rigidity of the adenine-binding pocket and hydrogen bonds are responsible for adenosine specificity. The nonconserved residues that interact with the substrate might be responsible for the species-dependent properties of an isozyme.