The closely related bacterial type II secretion (T2S) and type IV pilus (T4P) systems are sophisticated machines that assemble dynamic fibers promoting protein transport, motility, or adhesion. Despite their essential role in virulence, the molecular mechanisms underlying helical fiber assembly remain unknown. Here, we use electron microscopy and flexible modeling to study conformational changes of PulG pili assembled by the Klebsiella oxytoca T2SS. Neural network analysis of 3,900 pilus models suggested a transition path toward low-energy conformations driven by progressive increase in fiber helical twist. Detailed predictions of interprotomer contacts along this path were tested by site-directed mutagenesis, pilus assembly, and protein secretion analyses. We demonstrate that electrostatic interactions between adjacent protomers (P-P+1) in the membrane drive pseudopilin docking, while P-P+3 and P-P+4 contacts determine downstream fiber stabilization steps. These results support a model of a spool-like assembly mechanism for fibers of the T2SS-T4P superfamily.