Objectives To systematically assess the associations between various immune-mediated diseases (IMDs) and human papillomavirus (HPV)-associated diseases.Design Retrospective cohort study.Setting UK Biobank.Participants A total of 500 371 subjects aged 40–69 years were eligible for the analysis, after excluding those with prevalent HPV-associated diseases at baseline and those who had withdrawn their informed consent or lacked information on sex.Exposure Eighty IMDs (involving allergic/atopic diseases, autoimmune diseases, immunodeficiency diseases, etc) were identified in the UK Biobank.Primary and secondary outcome measures The main outcome was the incidence of HPV-associated diseases (including warts and malignancies of the cervix, oropharynx, anus, penis, vulva and vagina). Cox proportional hazards model was used to estimate HRs and 95% CIs with particular adjustment for sexual behaviours. We also conducted subgroup analyses based on benign and malignant status, and anatomical sites of HPV-associated diseases, respectively.Results During a median of 12.0 years of follow-up, 2244 cases out of 500 371 subjects developed HPV-associated diseases. Overall, participants with IMDs had a higher risk of HPV-associated diseases than their controls after adjustment for sexual behaviours and other potential confounders (female: HR=1.90, 95% CI=1.66 to 2.17, p