© 2016 Taglialegna et al. Biofilms are communities of bacteria that grow encased in an extracellular matrix that often contains proteins. The spatial organization and the molecular interactions between matrix scaffold proteins remain in most cases largely unknown. Here, we report that Bap protein of Staphylococcus aureus self-assembles into functional amyloid aggregates to build the biofilm matrix in response to environmental conditions. Specifically, Bap is processed and fragments containing at least the N-terminus of the protein become aggregation-prone and self-assemble into amyloid-like structures under acidic pHs and low concentrations of calcium. The molten globule-like state of Bap fragments is stabilized upon binding of the cation, hindering its self-assembly into amyloid fibers. These findings define a dual function for Bap, first as a sensor and then as a scaffold protein to promote biofilm development under specific environmental conditions. Since the pH-driven multicellular behavior mediated by Bap occurs in coagulase-negative staphylococci and many other bacteria exploit Bap-like proteins to build a biofilm matrix, the mechanism of amyloid-like aggregation described here may be widespread among pathogenic bacteria.