Background: Pregnant women with pre-existing mental illnesses have increased risks of adverse obstetric and neonatal outcomes compared with pregnant women without pre-existing mental illnesses. We aimed to estimate these differences in risks according to the highest level of pre-pregnancy specialist mental health care, defined as psychiatric hospital admission, crisis resolution team (CRT) contact, or specialist community care only, and the timing of the most recent care episode in the 7 years before pregnancy. Methods: Hospital and birth registration records of women with singleton births between April 1, 2014, and March 31, 2018 in England were linked to records of babies and records from specialist mental health services provided by the England National Health Service, a publicly funded health-care system. We compared the risks of adverse pregnancy outcomes, including fetal and neonatal death, preterm birth, and babies being born small for gestational age (SGA; birthweight <10th percentile), and composite indicators for neonatal adverse outcomes and maternal morbidity, between women with and without a history of contact with specialist mental health care. We calculated odds ratios adjusted for maternal characteristics (aORs), using logistic regression. Findings: Of 2 081 043 included women (mean age 30·0 years; range 18–55 years; 77·7% White, 11·4% South Asian, 4·7% Black, and 6·2% mixed or other ethnic background), 151 770 (7·3%) had at least one pre-pregnancy specialist mental health-care contact. 7247 (0·3%) had been admitted to a psychiatric hospital, 29 770 (1·4%) had CRT contact, and 114 753 (5·5%) had community care only. With a pre-pregnancy mental health-care contact, risk of stillbirth or neonatal death within 7 days of birth was not significantly increased (0·45–0·49%; aOR 1·11, 95% CI 0·99–1·24): risk of preterm birth (<37 weeks) increased (6·5–9·8%; aOR 1·53, 1·35–1·73), as did risk of SGA (6·2– 7·5%; aOR 1·34, 1·30–1·37) and neonatal adverse outcomes (6·4–8·4%; aOR 1·37, 1·21–1·55). With a pre-pregnancy mental health-care contact, risk of maternal morbidity increased slightly from 0·9% to 1·0% (aOR 1·18, 1·12–1·25). Overall, risks were highest for women who had a psychiatric hospital admission any time or a mental health-care contact in the year before pregnancy. Interpretation: Information about the level and timing of pre-pregnancy specialist mental health-care contacts helps to identify women at increased risk of adverse obstetric and neonatal outcomes. These women are most likely to benefit from dedicated community perinatal mental health teams working closely with maternity services to provide integrated care. Funding: National Institute for Health Research.