During chronic infection and cancer, a self-renewing CD8+ T cell subset maintains long-term immunity and is critical to the effectiveness of immunotherapy. These stem-like CD8+ T cells diverge from other CD8+ subsets early after chronic viral infection. However, pathways guarding stem-like CD8+ T cells against terminal exhaustion remain unclear. Here, we show that the gene encoding transcriptional repressor BACH2 is transcriptionally and epigenetically active in stem-like CD8+ T cells but not terminally exhausted cells early after infection. BACH2 overexpression enforced stem-like cell fate, whereas BACH2 deficiency impaired stem-like CD8+ T cell differentiation. Single-cell transcriptomic and epigenomic approaches revealed that BACH2 established the transcriptional and epigenetic programs of stem-like CD8+ T cells. In addition, BACH2 suppressed the molecular program driving terminal exhaustion through transcriptional repression and epigenetic silencing. Thus, our study reveals a new pathway that enforces commitment to stem-like CD8+ lineage and prevents an alternative terminally exhausted cell fate.