The cognitive impairment resulting from stroke is purported to be associated with impaired neuronal structure and function. Transcranial Magnetic Stimulation (TMS) modulates neuronal or cortical excitability and inhibits cellular apoptosis, thereby enhancing spatial learning and memory in middle cerebral artery occlusion/reperfusion (MCAO/R) rats. In this study, we aimed to investigate whether Sterile alpha and Toll/interleukin receptor motif-containing protein 1 (SARM1), a pivotal Toll-like receptor adaptor molecule and its related mechanisms are involved in the ameliorating effect of TMS on cognitive function post-cerebral ischemia. We evaluated hippocampal injury in MCAO/R rats after one week of treatment with 10-Hz TMS at an early stage. The effect of SARM1 was more effectively assessed through lentivirus-mediated SARM1 overexpression. Various techniques, including FJB staining, HE staining, western blot, immunofluorescence, imunohistochemistry, and transmission electron microscopy, were employed to investigate the molecular biological and morphological alterations of axons, myelin sheaths and apoptosis in the hippocampus. Ultimately, Morris Water Maze was employed to evaluate the spatial learning and memory capabilities of the rats. We observed that TMS significantly reduced the levels of SARM1, NF-κB, and Bax following MCAO/R, while elevating the levels of HSP70, Bcl-2, GAP-43, NF-200, BDNF, and MBP. Overexpression of SARM1 not only reversed the neuroprotective effects induced by TMS but also exacerbated spatial learning and memory impairments in rats. Our results demonstrate that TMS mitigates hippocampal cell apoptosis via the SARM1/HSP70/NF-κB signaling pathway, thus fostering the regeneration of hippocampal axons and myelin sheaths, as well as the improvement of spatial learning and memory.