Most bacterial vaccines work for a subset of bacterial strains or require the modification of the antigen or isolation of the pathogen before vaccine development. Here we report injectable biomaterial vaccines that trigger potent humoral and T-cell responses to bacterial antigens by recruiting, reprogramming and releasing dendritic cells. The vaccines are assembled from regulatorily approved products and consist of a scaffold with absorbed granulocyte-macrophage colony-stimulating factor and CpG-rich oligonucleotides incorporating superparamagnetic microbeads coated with the broad-spectrum opsonin Fc-mannose-binding lectin for the magnetic capture of pathogen-associated molecular patterns from inactivated bacterial-cell-wall lysates. The vaccines protect mice against skin infection with methicillin-resistant Staphylococcus aureus, mice and pigs against septic shock from a lethal Escherichia coli challenge and, when loaded with pathogen-associated molecular patterns isolated from infected animals, uninfected animals against a challenge with different E. coli serotypes. The strong immunogenicity and low incidence of adverse events, a modular manufacturing process, and the use of components compatible with current good manufacturing practice could make this vaccine technology suitable for responding to bacterial pandemics and biothreats.