Mitochondria, chloroplasts and Gram-negative bacteria are encased in a double layer of membranes. The outer membrane contains proteins with a $\beta$-barrel structure1,2. $\beta$-Barrels are sheets of $\beta$-strands wrapped into a cylinder, in which the first strand is hydrogen-bonded to the final strand. Conserved multi-subunit molecular machines fold and insert these proteins into the outer membrane3–5. One subunit of the machines is itself a $\beta$-barrel protein that has a central role in folding other $\beta$-barrels. In Gram-negative bacteria, the $\beta$-barrel assembly machine (BAM) consists of the $\beta$-barrel protein BamA, and four lipoproteins5–8. To understand how the BAM complex accelerates folding without using exogenous energy (for example, ATP)9, we trapped folding intermediates on this machine. Here we report the structure of the BAM complex of Escherichia coli folding BamA itself. The BamA catalyst forms an asymmetric hybrid $\beta$-barrel with the BamA substrate. The N-terminal edge of the BamA catalyst has an antiparallel hydrogen-bonded interface with the C-terminal edge of the BamA substrate, consistent with previous crosslinking studies10–12; the other edges of the BamA catalyst and substrate are close to each other, but curl inward and do not pair. Six hydrogen bonds in a membrane environment make the interface between the two proteins very stable. This stability allows folding, but creates a high kinetic barrier to substrate release after folding has finished. Features at each end of the substrate overcome this barrier and promote release by stepwise exchange of hydrogen bonds. This mechanism of substrate-assisted product release explains how the BAM complex can stably associate with the substrate during folding and then turn over rapidly when folding is complete.