Maternal infections during pregnancy are associated with intellectual disability and autism in exposed children. Whether these associations are causal, and therefore should be targets of preventive strategies, remains unknown. We aimed to investigate these associations, to determine whether there is a causal role of maternal infection during pregnancy for children's risk of autism and intellectual disability, by accounting for unmeasured familial factors. We used a register-based cohort study design, and included children living in Stockholm County, Sweden, who were born in 1987-2010. We excluded children not born in Sweden, adopted children, and children with unknown biological mothers or fathers. Maternal infections during pregnancy, defined by ICD-8, ICD-9, and ICD-10 codes, were identified in the National Patient Register and Medical Birth Register. Children were followed up from birth to an outcome or a censoring event (death, migration from Stockholm, age 18 years, or Dec 31, 2016, whichever occurred first). The primary outcomes were diagnosis of autism or diagnosis of intellectual disability. We did a survival analysis to examine the association between inpatient and outpatient specialised care for any infection during pregnancy and likelihood of autism or intellectual disability in the child. To address potential residual confounding, we also estimated the relationship between maternal infection in the year preceding pregnancy as a negative control exposure and conducted a matched sibling analysis of sibling pairs who were discordant for autism or intellectual disability. 647 947 children living in Stockholm County were identified and, after excluding 97 980 children, we included 549 967 in the study (267 995 [48·7%] were female and 281 972 [51·3%] were male; mean age at censoring 13·5 years [SD 5·0; range <1 to 18]; 142 597 [25·9%] had a mother who was not born in Sweden). 445 (1·3%) of 34 013 children exposed to maternal infection during pregnancy were diagnosed with intellectual disability and 1123 (3·3%) with autism. 5087 (1·0%) of 515 954 unexposed children were diagnosed with intellectual disability and 13 035 (2·5%) with autism. Maternal infection during pregnancy was associated with autism (hazard ratio [HR] 1·16, 95% CI 1·09-1·23) and intellectual disability (1·37, 1·23-1·51) in exposed children compared with unexposed children. Maternal infection in the year before pregnancy (negative control exposure) was also associated with autism (HR 1·25, 95% CI 1·14-1·36), but was not associated with intellectual disability (1·09, 0·94-1·27). In sibling comparisons, the associations with maternal infection during pregnancy were attenuated for autism (HR 0·94, 95% CI 0·82-1·08; n=21 864), but not to the same extent for intellectual disability (1·15, 0·95-1·40; n=9275). Although infections in pregnant women are associated with both autism and intellectual disability in their children, the association with autism does not appear to reflect a causal relationship, but is more likely to be explained by factors shared between family members such as genetic variation or aspects of the shared environment. Thus, infection prevention is not expected to reduce autism incidence. For intellectual disability, unmeasured familial factors might not fully explain the observed associations, and a causal role of maternal infections cannot be excluded. Causal effects of specific but rare infections or infections not requiring health care contact cannot be excluded in either autism or intellectual disability. Swedish Research Council, Stanley Medical Research Institute, and Autism Speaks. For the Swedish translation of the abstract see Supplementary Materials section.