Gestational diabetes mellitus (GDM) is a significant risk factor for autism spectrum disorder (ASD) in offspring. Despite the growing interest in the hypothesis of 5-hydroxytryptamine (5-HT) system dysfunction, the underlying mechanisms remain unclear and require further investigation. In this study, a GDM model was established in mice by feeding them a high fat diet (HFD) and administering an intraperitoneal injection of streptozocin (STZ). Our findings indicated that GDM exposure induced ASD-like behaviors and disrupted 5-HT system function by decreasing the level of Abelson helper integration site 1 (Ahi1) in the dorsal raphe nucleus (DRN) of male offspring. Furthermore, GDM evoked neuroinflammation, accompanied by a notable increase in the concentrations of proinflammatory factors (TNF-α, IL-1βand IL-6). Additionally, Ahi1 knockdown in normal mice mediated by an injection of AAV-Ahi1 in the brain recapitulated ASD-like behaviors and 5-HT system dysfunction, but these effects were blocked by the overexpression of B9 domain-containing protein 1 (B9D1) or meptazinol-mediated pharmacological activation of Ahi1, which ameliorated ASD-like behaviors, neuroinflammation and reversed 5-HT system dysfunction in male offspring of mothers with GDM (GDM-Os). Furthermore, lipopolysaccharide (LPS) induced neuroinflammation inhibited Ahi1 induced 5-HT system dysfunctions in vitro. Based on these findings, the inhibitory effects of meptazinol on GDM-induced ASD-like behaviors could be attributed to the involvement of 5-HT system dysfunction mediated by the Ahi1/B9D1/Shh axis. These findings provide novel insights into the mechanism by which neuroinflammation associated with GDM causes ASD pathogenesis and may pave the way for the development of a new therapeutic strategies for ASD.