Introduction: Cognitive impairment is a common complication and comorbidity of diabetes. However, the underlying mechanisms of diabetes-associated cognitive dysfunction are currently unclear. M1 microglia secretes pro-inflammatory factors and can be marked by CD16, iNOS, Iba1 and TNF-ɑ. The decline of M2 microglia in the diabetic rats indicates that high glucose promotes the differentiation of microglia into the M1 type to trigger neuroinflammatory responses. Moreover, there is a lack of strong evidence for treatments of diabetes-associated cognitive impairment in addition to controlling blood glucose.Methods: Diabetic rats were established by intraperitoneal injection of one dose of streptozotocin (60 mg/kg). Polarization transitions of microglia were induced by high glucose treatment in BV2 cells. Levetiracetam was orally administered to rats 72 h after streptozotocin injection for 12 weeks.Results: In STZ-induced diabetic rats, the results demonstrated that levetiracetam improved rat cognitive function (Morris water maze test) and hippocampus morphology (Hematoxylin-eosin staining), and the effect was more evident in the high-dose levetiracetam group. Microglia activation in the hippocampus was inhibited by levetiracetam treatment for 12 weeks. Serum levels of TNF-α, IL-1β, and IL-6 were reduced in the LEV-L and LEV-H groups, and IL-1β level was obviously reduced in the LEV-H group. In vitro, we found that levetiracetam 50 µM attenuated high-glucose induced microglial polarization by increasing IL-10 level and decreasing IL-1β and TNF-α levels. Moreover, levetiracetam 50 µM increased and decreased the proportion of CD206+/Iba1+ and iNOS+/Iba1+cells, respectively. Western blot analysis illustrated that LEV 50 µM downregulated the expression of MyD88 and TRAF6, and phosphorylation of TAK1, JNK, p38, and NF-κB p65. The effect of levetiracetam on the anti-polarization and expression of p-JNK and p-NF-κB p65 were partly reversed by anisomycin (p38 and JNK activators).Discussion: Together, our data suggest that levetiracetam attenuates streptozotocin-induced cognitive impairment by suppressing microglia activation. The in vitro findings also indicate that the levetiracetam inhibited the polarization of microglia via the JNK/MAPK/NF-κB signaling pathway.