The immune system evolved to efficiently eradicate invading bacteria and terminate inflammation through balancing inflammatory and regulatory T-cell responses. In autoimmune arthritis, pathogenic TH17 cells induce bone destruction and autoimmune inflammation. However, whether a beneficial function of T-cell-induced bone damage exists is unclear. Here, we show that bone-damaging T cells have a critical function in the eradication of bacteria in a mouse model of periodontitis, which is the most common infectious disease. Bacterial invasion leads to the generation of specialized TH17 cells that protect against bacteria by evoking mucosal immune responses as well as inducing bone damage, the latter of which also inhibits infection by removing the tooth. Thus, bone-damaging T cells, which may have developed to stop local infection by inducing tooth loss, function as a double-edged sword by protecting against pathogens while also inducing skeletal tissue degradation.