Sleep deprivation (SD) is commonplace in today's fast-paced society. SD is a severe public health problem globally since it may cause cognitive decline and even neurodegenerative disorders like Alzheimer's disease. Melatonin (MT) is a natural chemical secreted by the pineal gland with neuroprotective effects. The purpose of this study was to investigate the protective effect and mechanism of MT on chronic sleep deprivation-induced cognitive impairment. A 3-week modified multi-platform method was used to create the SD rat model. The Morris water maze test (MWM), Tissue staining (including Hematoxylin and Eosin (H & E) staining, Nissl staining, and immunofluorescence), Western blot, Enzyme-linked immunosorbent assay (ELISA), and Quantitative real-time polymerase chain reaction (qPCR) were used to investigate the protective effect and mechanism of MT in ameliorating cognitive impairment in SD rats. The results showed that MT (50 and 100mg/kg) significantly improved cognitive function in rats, as evidenced by a shortening of escape latency and increased time of crossing the platform and time spent in the quadrant. Additionally, MT therapy alleviated hippocampus neurodegeneration and neuronal loss while lowering levels of pathogenic factors (LPS) and inflammatory indicators (IL-1β, IL-6, TNF-α, iNOS, and COX2). Furthermore, MT treatment reversed the high expression of Aβ42 and Iba1 as well as the low expression of ZO-1 and occludin, and inhibited the SD-induced TLR4/MyD88/NF-κB signaling pathway. In summary, MT ameliorated spatial recognition and learning memory dysfunction in SD rats by reducing neuroinflammation and increasing neuroprotection while inhibiting the TLR4/MyD88/NF-κB signaling pathway. Our study supports the use of MT as an alternate treatment for SD with cognitive impairment.