In the context of immune-mediated inflammatory diseases (IMIDs), COVID-19 outcomes are incompletely understood and vary considerably depending on the patient population studied. We aimed to analyse severe COVID-19 outcomes and to investigate the effects of the pandemic time period and the risks associated with individual IMIDs, classes of immunomodulatory medications (IMMs), chronic comorbidities, and COVID-19 vaccination status. In this retrospective cohort study, clinical data were derived from the electronic health records of an integrated health-care system serving patients in 51 hospitals and 1085 clinics across seven US states (Providence St Joseph Health). Data were observed for patients (no age restriction) with one or more IMID and for unmatched controls without IMIDs. COVID-19 was identified with a positive nucleic acid amplification test result for SARS-CoV-2. Two timeframes were analysed: March 1, 2020-Dec 25, 2021 (pre-omicron period), and Dec 26, 2021-Aug 30, 2022 (omicron-predominant period). Primary outcomes were hospitalisation, mechanical ventilation, and mortality in patients with COVID-19. Factors, including IMID diagnoses, comorbidities, long-term use of IMMs, and COVID-19 vaccination status, were analysed with multivariable logistic regression (LR) and extreme gradient boosting (XGB). Of 2 167 656 patients tested for SARS-CoV-2, 290 855 (13·4%) had confirmed COVID-19: 15 397 (5·3%) patients with IMIDs and 275 458 (94·7%) without IMIDs. In the pre-omicron period, 169 993 (11·2%) of 1 517 295 people who were tested for COVID-19 tested positive, of whom 23 330 (13·7%) were hospitalised, 1072 (0·6%) received mechanical ventilation, and 5294 (3·1%) died. Compared with controls, patients with IMIDs and COVID-19 had higher rates of hospitalisation (1176 [14·6%] vs 22 154 [13·7%]; p=0·024) and mortality (314 [3·9%] vs 4980 [3·1%]; p<0·0001). In the omicron-predominant period, 120 862 (18·6%) of 650 361 patients tested positive for COVID-19, of whom 14 504 (12·0%) were hospitalised, 567 (0·5%) received mechanical ventilation, and 2001 (1·7%) died. Compared with controls, patients with IMIDs and COVID-19 (7327 [17·3%] of 42 249) had higher rates of hospitalisation (13 422 [11·8%] vs 1082 [14·8%]; p<0·0001) and mortality (1814 [1·6%] vs 187 [2·6%]; p<0·0001). Age was a risk factor for worse outcomes (adjusted odds ratio [OR] from 2·1 [95% CI 2·0-2·1]; p<0·0001 to 3·0 [2·9-3·0]; p<0·0001), whereas COVID-19 vaccination (from 0·082 [0·080-0·085]; p<0·0001 to 0·52 [0·50-0·53]; p<0·0001) and booster vaccination (from 2·1 [2·0-2·2]; p<0·0001 to 3·0 [2·9-3·0]; p<0·0001) status were associated with better outcomes. Seven chronic comorbidities were significant risk factors during both time periods for all three outcomes: atrial fibrillation, coronary artery disease, heart failure, chronic kidney disease, chronic obstructive pulmonary disease, chronic liver disease, and cancer. Two IMIDs, asthma (adjusted OR from 0·33 [0·32-0·34]; p<0·0001 to 0·49 [0·48-0·51]; p<0·0001) and psoriasis (from 0·52 [0·48-0·56] to 0·80 [0·74-0·87]; p<0·0001), were associated with a reduced risk of severe outcomes. IMID diagnoses did not appear to be significant risk factors themselves, but results were limited by small sample size, and vasculitis had high feature importance in LR. IMMs did not appear to be significant, but less frequently used IMMs were limited by sample size. XGB outperformed LR, with the area under the receiver operating characteristic curve for models across different time periods and outcomes ranging from 0·77 to 0·92. Our results suggest that age, chronic comorbidities, and not being fully vaccinated might be greater risk factors for severe COVID-19 outcomes in patients with IMIDs than the use of IMMs or the IMIDs themselves. Overall, there is a need to take age and comorbidities into consideration when developing COVID-19 guidelines for patients with IMIDs. Further research is needed for specific IMIDs (including IMID severity at the time of SARS-CoV-2 infection) and IMMs (considering dosage and timing before a patient's first COVID-19 infection). Pfizer, Novartis, Janssen, and the National Institutes of Health.