The bacterial flagellum is essential for motility, adhesion, and colonization in pathogens like Salmonella enterica and Campylobacter jejuni. Its extracellular structure comprises the hook, hook-filament junction, filament, and filament cap. The native structures of the hook-filament junction and the cap remain elusive, leaving the molecular details of cap-mediated filament assembly largely uncharacterized. Here, we report the structure of the complete extracellular flagellum, encompassing the hook, hook-filament junction, filament, and cap. This structure reveals intermediates of filament assembly, providing a molecular blueprint for flagellin folding and insertion at the filament tip. Mutagenesis and functional assays demonstrate the crucial roles of the terminal regions of the cap in flagellin incorporation, and of the structural integrity of the hook-filament junction. Finally, the structure of the cap and hook-filament junction prior to filament assembly reveals the structural basis for the initiation of filament assembly. Collectively, this study provides comprehensive insights into flagellum assembly and how flagellin incorporation is coupled with its secretion.