The present study aims to evaluate the effects of pterostilbene on lipopolysaccharide (LPS)-induced learning and memory impairment as well as the possible changes of microglia and neurons. Firstly, learning and memory function was investigated by behavioral tests. Pterostilbene attenuated LPS-induced learning and memory impairment tested by Y-maze and Morris water maze. Secondly, immunohistochemical method was used to study the changes of microglia and neurons. The results showed that pterostilbene produced a significant decrease in the number of Iba-1 and Doublecortin (DCX) positive cells and a significant increase in neuronal nuclear antigen (NeuN)-stained area of neurons in mouse hippocampal compared to the LPS group. Finally, an in vitro study was performed to further confirm the inhibitory effect on microglia activation and protective effect on neurons exerted by pterostilbene. The results demonstrated that pterostilbene significantly inhibited microglia activation, showing the obvious decrease of LPS-induced production of NO, TNF-α and IL-6 in N9 microglial cells. In addition, the viability of SH-SY5Y cells decreased by conditioned media of LPS-activated N9 microglial cells was remarkably recovered by pterostilbene. In summary, the present study demonstrated for the first time that pterostilbene attenuated LPS-induced learning and memory impairment, which may be associated with its inhibitory effect on microglia activation and protective effect on neuronal injury.