Many bacteria in nature exist in multicellular communities termed biofilms, where cells are embedded in an extracellular matrix that provides rigidity to the biofilm and protects cells from chemical and mechanical stresses. In the Gram-positive model bacterium Bacillus subtilis, TasA is the major protein component of the biofilm matrix, where it has been reported to form functional amyloid fibres contributing to biofilm structure and stability. Here, we present electron cryomicroscopy structures of TasA fibres, which show that, rather than forming amyloid fibrils, TasA monomers assemble into fibres through donor-strand exchange, with each subunit donating a β-strand to complete the fold of the next subunit along the fibre. Combining electron cryotomography, atomic force microscopy, and mutational studies, we show how TasA fibres congregate in three dimensions to form abundant fibre bundles that are essential for B. subtilis biofilm formation. Our study explains the previously observed biochemical properties of TasA and shows how a bacterial extracellular globular protein can assemble from monomers into β-sheet-rich fibres, and how such fibres assemble into bundles in biofilms.