Biofilm formation mediated by sortase A (srtA) is important for bacterial colonisation and resistance to antibiotics. Thus, the inhibitor of SrtA may represent a promising agent for bacterial infection. The structure of Streptococcus pneumoniae D39 srtA has been characterised by crystallisation. Site‐directed mutagenesis was used for the determination of the key residues for the activity of S. pneumoniae D39 srtA. An effective srtA inhibitor, quercetin, and its mechanism was further identified using srtA activity inhibition assay and molecular modelling. In this study, the crystal structure of S. pneumoniae D39 srtA has been solved and shown to contain a unique domain B. Additionally, its transpeptidase activity was evaluated in vitro. Based on the structure, we identified Cys207 as the catalytic residue, with His141 and Arg215 serving as binding sites for the peptide substrate. We found that quercetin can specifically compete with the natural substrate, leading to a significant decrease in the catalytic activity of this enzyme. In cells co‐cultured with this small molecule inhibitor, NanA cannot anchor to the cell wall effectively, and biofilm formation and biomass decrease significantly. Interestingly, when we supplemented cultures with sialic acid, a crucial signal for pneumococcal coloniation and the invasion of the host in the co‐culture system, biofilm loss did not occur. This result indicates that quercetin inhibits biofilm formation by affecting sialic acid production. In conclusion, the inhibition of pneumococcal srtA by the small molecule quercetin offers a novel strategy for pneumococcal preventative therapy.