The environment, diet, microbiota and body's metabolism shape complex biological processes in health and disease. However, our understanding of the molecular pathways involved in these processes is still limited. The aryl hydrocarbon receptor (AHR) is a ligand-activated transcription factor that integrates environmental, dietary, microbial and metabolic cues to control complex transcriptional programmes in a ligand-specific, cell-type-specific and context-specific manner. In this Review, we summarize our current knowledge of AHR and the transcriptional programmes it controls in the immune system. Finally, we discuss the role of AHR in autoimmune and neoplastic diseases of the central nervous system, with a special focus on the gut immune system, the gut-brain axis and the therapeutic potential of targeting AHR in neurological disorders.