CD4+ T helper 17 (TH17) cells protect barrier tissues but also trigger autoimmunity. The mechanisms behind these opposing processes remain unclear. Here, we found that the transcription factor EGR2 controlled the transcriptional program of pathogenic TH17 cells in the central nervous system (CNS) but not that of protective TH17 cells at barrier sites. EGR2 was significantly elevated in myelin-reactive CD4+ T cells from patients with multiple sclerosis and mice with autoimmune neuroinflammation. The EGR2 transcriptional program was intricately woven within the TH17 cell transcriptional regulatory network and showed high interconnectivity with core TH17 cell-specific transcription factors. Mechanistically, EGR2 enhanced TH17 cell differentiation and myeloid cell recruitment to the CNS by upregulating pathogenesis-associated genes and myelomonocytic chemokines. T cell-specific deletion of Egr2 attenuated neuroinflammation without compromising the host’s ability to control infections. Our study shows that EGR2 regulates tissue-specific and disease-specific functions in pathogenic TH17 cells in the CNS.