Neurosurgery always results in neuroinflammation, which may activate microglial cells. Previous studies have demonstrated that fentanyl could be used for the induction or maintenance of anesthesia prior to surgery. However, it is unknown if fentanyl attenuates neuroinflammation prophylactically. Cell viability in groups that were treated with different concentrations of fentanyl (0.01, 0.1, 1 or 5 µmol/l) was analyzed by an MTT assay. BV-2 microglial cells were treated with lipopolysaccharide (LPS) at a concentration of 1 µg/ml to mimic neuroinflammation . BV-2 cells were pretreated with 5 µmol/l fentanyl prior to stimulation by LPS. The protein levels of tumor necrosis factor (TNF)-α, interleukin (IL)-1β and IL-10 in the culture medium were assessed by ELISA. The mRNA level of toll-like receptor (TLR)4 was evaluated by reverse transcription-quantitative polymerase chain reaction analysis. The protein levels of TLR4, glycogen synthase kinase (GSK)-3β and phosphorylated (p)-GSK-3β in BV-2 cells were assessed by western blot analysis. The MTT assay demonstrated that low concentrations of fentanyl (0.01, 0.1 or 1 µmol/l) did not affect the cell viability of BV-2 cells, while 5 µmol/l fentanyl significantly reduced BV-2 cell viability. The results of ELISA revealed that LPS significantly upregulated the release of TNF-α, IL-1β and IL-10, which were repressed by fentanyl pretreatment. Fentanyl pretreatment significantly reduced the LPS-induced elevation of TLR4 at mRNA and protein levels as well as p-GSK-3β protein levels in BV-2 cells. In conclusion, fentanyl pretreatment protects BV-2 cells from LPS-induced neuroinflammation by inhibiting TLR4 expression and GSK-3β activation. Neuroinflammation induced by surgery serves an important role in the development of postoperative cognitive dysfunction (POCD) and targeting the TLR4 and GSK-3β signaling pathway may provide a novel therapeutic approach for the treatment of POCD.