Our objective was to estimate the relative risk of IBD among first-generation and second-generation immigrants in Denmark compared with native Danes.Using national registries, we established a cohort of Danish residents between 1977 and 2018. Cohort members with known country of birth were followed for Crohn's disease (CD) and ulcerative colitis (UC) diagnoses. Incidence rate ratios (IRRs) served as measures of relative risk and were calculated by log-linear Poisson regression, using rates among native Danes as reference, stratified by IBD risk in parental country of birth, and among first-generation immigrants by age at immigration and duration of stay in Denmark.Among 8.7 million Danes, 4156 first-generation and 898 second-generation immigrants were diagnosed with CD or UC. Overall, comparing first-generation immigrants with native Danes, the IRR was 0.80 (95% CI 0.76 to 0.84) for CD and 0.74 (95% CI 0.71 to 0.77) for UC. The IRR of IBD increased with ≥20 years stay in Denmark. The IRR of CD increased with immigration at ≥40 years of age. Comparing second-generation immigrants with native Danes, the IRR of IBD was 0.97 (95% CI 0.91 to 1.04). There was significant interaction with sex, with higher IRR of IBD in male than in female immigrants.Relative to native Danish men and women, IBD risk among first-generation immigrants was lower, reflected the risk in their parental country of birth and increased with ≥20 years stay in Denmark. For second-generation immigrants, relative risk of IBD was lower only among women. These complex patterns suggest the role of environmental IBD risk factors.