We aimed to ascertain the cumulative risk of fatal or critical care unit-treated COVID-19 in people with diabetes and compare it with that of people without diabetes, and to investigate risk factors for and build a cross-validated predictive model of fatal or critical care unit-treated COVID-19 among people with diabetes.In this cohort study, we captured the data encompassing the first wave of the pandemic in Scotland, from March 1, 2020, when the first case was identified, to July 31, 2020, when infection rates had dropped sufficiently that shielding measures were officially terminated. The participants were the total population of Scotland, including all people with diabetes who were alive 3 weeks before the start of the pandemic in Scotland (estimated Feb 7, 2020). We ascertained how many people developed fatal or critical care unit-treated COVID-19 in this period from the Electronic Communication of Surveillance in Scotland database (on virology), the RAPID database of daily hospitalisations, the Scottish Morbidity Records-01 of hospital discharges, the National Records of Scotland death registrations data, and the Scottish Intensive Care Society and Audit Group database (on critical care). Among people with fatal or critical care unit-treated COVID-19, diabetes status was ascertained by linkage to the national diabetes register, Scottish Care Information Diabetes. We compared the cumulative incidence of fatal or critical care unit-treated COVID-19 in people with and without diabetes using logistic regression. For people with diabetes, we obtained data on potential risk factors for fatal or critical care unit-treated COVID-19 from the national diabetes register and other linked health administrative databases. We tested the association of these factors with fatal or critical care unit-treated COVID-19 in people with diabetes, and constructed a prediction model using stepwise regression and 20-fold cross-validation.Of the total Scottish population on March 1, 2020 (n=5 463 300), the population with diabetes was 319 349 (5·8%), 1082 (0·3%) of whom developed fatal or critical care unit-treated COVID-19 by July 31, 2020, of whom 972 (89·8%) were aged 60 years or older. In the population without diabetes, 4081 (0·1%) of 5 143 951 people developed fatal or critical care unit-treated COVID-19. As of July 31, the overall odds ratio (OR) for diabetes, adjusted for age and sex, was 1·395 (95% CI 1·304-1·494; p<0·0001, compared with the risk in those without diabetes. The OR was 2·396 (1·815-3·163; p<0·0001) in type 1 diabetes and 1·369 (1·276-1·468; p<0·0001) in type 2 diabetes. Among people with diabetes, adjusted for age, sex, and diabetes duration and type, those who developed fatal or critical care unit-treated COVID-19 were more likely to be male, live in residential care or a more deprived area, have a COVID-19 risk condition, retinopathy, reduced renal function, or worse glycaemic control, have had a diabetic ketoacidosis or hypoglycaemia hospitalisation in the past 5 years, be on more anti-diabetic and other medication (all p<0·0001), and have been a smoker (p=0·0011). The cross-validated predictive model of fatal or critical care unit-treated COVID-19 in people with diabetes had a C-statistic of 0·85 (0·83-0·86).Overall risks of fatal or critical care unit-treated COVID-19 were substantially elevated in those with type 1 and type 2 diabetes compared with the background population. The risk of fatal or critical care unit-treated COVID-19, and therefore the need for special protective measures, varies widely among those with diabetes but can be predicted reasonably well using previous clinical history.None.