Abstract Microglia, the main immunocompetent cells of the brain regulate neuronal function in health and disease, but their contribution to cerebral blood flow (CBF) remained elusive. Here we identify microglia as important modulators of CBF both under physiological conditions and during hypoperfusion. We show that microglia establish direct purinergic contacts with cells in the neurovascular unit that shape cerebral perfusion in both mice and humans. Surprisingly, the absence of microglia or blockade of microglial P2Y12 receptor (P2Y12R) substantially impairs neurovascular coupling in the barrel cortex after whisker stimulation. We also reveal that hypercapnia, which is associated with acidification, induces microglial adenosine production, while depletion of microglia reduces brain pH and impairs hypercapnia-induced vasodilation. Furthermore, the absence or dysfunction of microglia markedly impairs adaptation to hypoperfusion via P2Y12R after transient unilateral common carotid artery occlusion, which is also influenced by CX3CR1-mediated actions. Thus, our data reveal a previously unrecognized role for microglia in CBF regulation with broad implications for common neurological diseases.