BackgroundGestational diabetes affects 4% of UK pregnancies, and women affected are estimated to be seven times as likely as those without the disorder to develop subsequent type 2 diabetes. We aimed to determine incidence of and risk factors for type 2 diabetes after a pregnancy affected by gestational diabetes. MethodsThis longitudinal population-based cohort made use of the Hampshire Health Record, a health-care database covering around 1·2 million residents in Hampshire, UK. All women diagnosed with gestational diabetes between Sept 30, 2007, and Sept 30, 2015, were identified. If women had multiple pregnancies affected by gestational diabetes during the study period, only the first pregnancy was included. Multivariable Cox proportional hazards regression modelling was used to assess clinically significant risk factors, based on previous evidence, that were available in the dataset including body-mass index (BMI) before pregnancy, ethnicity, family history of diabetes, treatment type for gestational diabetes, age (at time of diagnosis), area deprivation level, hypertension, hyperlipidaemia, cardiovascular disease, and a history of gestational diabetes. Diagnoses of type 2 diabetes during the study period were used to calculate incidence of type 2 diabetes after gestational diabetes. Findings3033 women with gestational diabetes were identified. 171 of 2654 women who were tested for type 2 diabetes during the study period (6·4%, 95% CI 5·5–7·3) were diagnosed with this condition (mean follow-up 4·1 years [SD 2·2]). Obesity was the strongest risk factor, with adjusted hazard ratios (aHR) for obesity (BMI 30–35 kg/m2) of 2·8 (95% CI 1·5–5·3) and for severe obesity (>35 g/m2) of 3·4 (1·5–7·8; p<0·0001 for trend). Other significant risk factors included Asian ethnicity (aHR 2·9, 95% CI 1·6–5·3), previous gestational diabetes (1·7, 1·1–2·6), and pharmacological treatment for gestational diabetes (insulin 2·9, 2·0–4·2; oral medications 1·9, 1·2–3·1). InterpretationRoutinely collected electronic health-care data can be used to assess real-life risk factors for type 2 diabetes after gestational diabetes. Challenges include missing data and inaccurate coding, which can impact validity of findings. However, this study provides a basis to develop and test a regional risk-scoring system for prioritising referrals to interventions for diabetes prevention after gestational diabetes. FundingThis study formed the basis of JB's MSc Public Health dissertation, which was funded by Health Education England as part of the Wessex Public Health Specialty Training Programme.