Microglial activation is a key event in neuroinflammation, which, in turn, is a central process in neurological disorders. In this study, we investigated the protective effects of D-beta-hydroxybutyrate (BHB) against microglial activation in lipopolysaccharide (LPS)-treated mice and BV-2 cells. The effects of BHB in mice were assessed using behavioral testing, morphological analysis and immunofluorescence labeling for the microglial marker ionizing calcium-binding adaptor molecule 1 (IBA-1) and the inflammatory cytokine interleukin-6 (IL-6) in the hippocampus. Moreover, we examined the levels of the inflammatory IL-6 and tumor necrosis factor-α (TNF-α), as well as those of the neuroprotective brain-derived neurotrophic factor (BDNF) and transforming growth factor-β (TGF-β) in the brain. In addition, we examined the effects of BHB on IL-6, TNF-α, BDNF, TGF-β, reactive oxygen species (ROS) level and cell viability in LPS-stimulated BV-2 cells. BHB treatments attenuated behavioral abnormalities, reduced the number of IBA-1-positive cells and the intensity of IL-6 fluorescence in the hippocampus, with amelioration of microglia morphological changes in the LPS-treated mice. Furthermore, BHB inhibited IL-6 and TNF-α generation, but promoted BDNF and TGF-β production in the brain of LPS-treated mice. In vitro, BHB inhibited IL-6 and TNF-α generation, increased BDNF and TGF-β production, reduced ROS level, ameliorated morphological changes and elevated cell viability of LPS-stimulated BV-2 cells. Together, our findings suggest that BHB exerts protective effects against microglial activation in vitro and in vivo, thereby reducing neuroinflammation.