Microglia, the resident myeloid cells of the central nervous system, play important roles in life-long brain maintenance and in pathology. Despite their crucial role, their regulatory dynamics during brain development have not been fully elucidated. Genome-wide chromatin and expression profiling coupled with single-cell transcriptomic analysis throughout development reveal that microglia undergo three temporal developmental stages in synchrony with the brain: early, pre-, and adult microglia, which are under distinct regulatory circuits. Knockout of the adult microglia transcription factor MafB and environmental perturbations, such as those affecting the microbiome or prenatal immune activation, led to disruption of developmental genes and immune response pathways. Together, our work identifies a stepwise developmental program of microglia integrating immune response pathways that may be associated with several neurodevelopmental disorders.