The gut microbiota synthesize hundreds of molecules, many of which influence host physiology. Among the most abundant metabolites are the secondary bile acids deoxycholic acid (DCA) and lithocholic acid (LCA), which accumulate at concentrations of around 500 μM and are known to block the growth of Clostridium difficile1, promote hepatocellular carcinoma2 and modulate host metabolism via the G-protein-coupled receptor TGR5 (ref. 3). More broadly, DCA, LCA and their derivatives are major components of the recirculating pool of bile acids4; the size and composition of this pool are a target of therapies for primary biliary cholangitis and nonalcoholic steatohepatitis. Nonetheless, despite the clear impact of DCA and LCA on host physiology, an incomplete knowledge of their biosynthetic genes and a lack of genetic tools to enable modification of their native microbial producers limit our ability to modulate secondary bile acid levels in the host. Here we complete the pathway to DCA and LCA by assigning and characterizing enzymes for each of the steps in its reductive arm, revealing a strategy in which the A-B rings of the steroid core are transiently converted into an electron acceptor for two reductive steps carried out by Fe-S flavoenzymes. Using anaerobic in vitro reconstitution, we establish that a set of six enzymes is necessary and sufficient for the eight-step conversion of cholic acid to DCA. We then engineer the pathway into Clostridium sporogenes, conferring production of DCA and LCA on a nonproducing commensal and demonstrating that a microbiome-derived pathway can be expressed and controlled heterologously. These data establish a complete pathway to two central components of the bile acid pool.