A subset of children with autism spectrum disorder appear to show an improvement in their behavioural symptoms during the course of a fever, a sign of systemic inflammation1,2. Here we elucidate the molecular and neural mechanisms that underlie the beneficial effects of inflammation on social behaviour deficits in mice. We compared an environmental model of neurodevelopmental disorders in which mice were exposed to maternal immune activation (MIA) during embryogenesis3,4 with mouse models that are genetically deficient for contactin-associated protein-like 2 (Cntnap2)5, fragile X mental retardation-1 (Fmr1)6 or Sh3 and multiple ankyrin repeat domains 3 (Shank3)7. We establish that the social behaviour deficits in offspring exposed to MIA can be temporarily rescued by the inflammatory response elicited by the administration of lipopolysaccharide (LPS). This behavioural rescue was accompanied by a reduction in neuronal activity in the primary somatosensory cortex dysgranular zone (S1DZ), the hyperactivity of which was previously implicated in the manifestation of behavioural phenotypes associated with offspring exposed to MIA8. By contrast, we did not observe an LPS-induced rescue of social deficits in the monogenic models. We demonstrate that the differences in responsiveness to the LPS treatment between the MIA and the monogenic models emerge from differences in the levels of cytokine production. LPS treatment in monogenic mutant mice did not induce amounts of interleukin-17a (IL-17a) comparable to those induced in MIA offspring; bypassing this difference by directly delivering IL-17a into S1DZ was sufficient to promote sociability in monogenic mutant mice as well as in MIA offspring. Conversely, abrogating the expression of IL-17 receptor subunit a (IL-17Ra) in the neurons of the S1DZ eliminated the ability of LPS to reverse the sociability phenotypes in MIA offspring. Our data support a neuroimmune mechanism that underlies neurodevelopmental disorders in which the production of IL-17a during inflammation can ameliorate the expression of social behaviour deficits by directly affecting neuronal activity in the central nervous system.