Summary: Ischemic stroke is the second leading cause of death and disability worldwide, and efforts to prevent stroke, mitigate secondary neurological damage, and promote neurological recovery remain paramount. Recent findings highlight the critical importance of microbiome-related metabolites, including vitamin B12 (VB12), in alleviating toxic stroke-associated neuroinflammation. Here, we showed that VB12 tonically programmed genes supporting microglial cell division and activation and critically controlled cellular fatty acid metabolism in homeostasis. Intriguingly, VB12 promoted mitochondrial transcriptional and metabolic activities and significantly restricted stroke-associated gene alterations in microglia. Furthermore, VB12 differentially altered the functions of microglial subsets during the acute phase of ischemic stroke, resulting in reduced brain damage and improved neurological function. Pharmacological depletion of microglia before ischemic stroke abolished VB12-mediated neurological improvement. Thus, our preclinical studies highlight the relevance of VB12 in the functional programming of microglia to alleviate neuroinflammation, minimize ischemic injury, and improve host neurological recovery after ischemic stroke.