During unresolved infections, some viruses escape immunological control and establish a persistant reservoir in certain cell types, such as human immunodeficiency virus (HIV), which persists in follicular helper T cells (TFH cells), and Epstein-Barr virus (EBV), which persists in B cells. Here we identified a specialized group of cytotoxic T cells (TC cells) that expressed the chemokine receptor CXCR5, selectively entered B cell follicles and eradicated infected TFH cells and B cells. The differentiation of these cells, which we have called 'follicular cytotoxic T cells' (TFC cells), required the transcription factors Bcl6, E2A and TCF-1 but was inhibited by the transcriptional regulators Blimp1, Id2 and Id3. Blimp1 and E2A directly regulated Cxcr5 expression and, together with Bcl6 and TCF-1, formed a transcriptional circuit that guided TFC cell development. The identification of TFC cells has far-reaching implications for the development of strategies to control infections that target B cells and TFH cells and to treat B cell-derived malignancies.