The aryl hydrocarbon receptor (AhR) is a highly conserved ligand-dependent transcription factor that senses environmental toxins and endogenous ligands, thereby inducing detoxifying enzymes and modulating immune cell differentiation and responses. We hypothesized that AhR evolved to sense not only environmental pollutants but also microbial insults. We characterized bacterial pigmented virulence factors, namely the phenazines from Pseudomonas aeruginosa and the naphthoquinone phthiocol from Mycobacterium tuberculosis, as ligands of AhR. Upon ligand binding, AhR activation leads to virulence factor degradation and regulated cytokine and chemokine production. The relevance of AhR to host defence is underlined by heightened susceptibility of AhR-deficient mice to both P. aeruginosa and M. tuberculosis. Thus, we demonstrate that AhR senses distinct bacterial virulence factors and controls antibacterial responses, supporting a previously unidentified role for AhR as an intracellular pattern recognition receptor, and identify bacterial pigments as a new class of pathogen-associated molecular patterns.