Cofactor F420 plays critical roles in primary and secondary metabolism in a range of bacteria and archaea as a low-potential hydride transfer agent. It mediates a variety of important redox transformations involved in bacterial persistence, antibiotic biosynthesis, pro-drug activation and methanogenesis. However, the biosynthetic pathway for F420 has not been fully elucidated: neither the enzyme that generates the putative intermediate 2-phospho-L-lactate, nor the function of the FMN-binding C-terminal domain of the γ-glutamyl ligase (FbiB) in bacteria are known. Here we present the structure of the guanylyltransferase FbiD and show that, along with its archaeal homolog CofC, it accepts phosphoenolpyruvate, rather than 2-phospho-L-lactate, as the substrate, leading to the formation of the previously uncharacterized intermediate dehydro-F420-0. The C-terminal domain of FbiB then utilizes FMNH2 to reduce dehydro-F420-0, which produces mature F420 species when combined with the γ-glutamyl ligase activity of the N-terminal domain. These new insights have allowed the heterologous production of F420 from a recombinant F420 biosynthetic pathway in Escherichia coli.