The relationship between uterine corpus cancer and endometriosis was conflicting. We aimed to determine the risk of uterine cancer in patients with endometriosis or pelvic inflammatory disease (PID). In this population-based cohort study, a total of 135,236 females with endometriosis (n = 20,510) or PID (n = 114,726), as well as 135,236 age-matched controls, were included. Cox regression models estimated the risk of uterine cancer in each group. Sub-outcomes of risk for uterine corpus cancer included endometrial cancer and uterine sarcoma were analyzed. An age subgroup analysis was performed to determine the moderator effect of age. A landmark analysis depicted the time varying effect of endometriosis and PID. A propensity score matching analysis was conducted to validate the findings. Patients with endometriosis had significantly higher risk of endometrial cancer (adjusted hazard ratio, aHR = 2.92; 95% CI = 2.12–4.03) and uterine sarcoma (aHR = 5.83; 95% CI = 2.02–16.89), while PID was not associated with the risk of uterine cancer. The increased risk of uterine cancer in patients with endometriosis persisted after propensity score matching (aHR = 2.83, 95%CI = 1.70–4.71). The greatest risk of endometrial cancer occurred in patients who had endometriosis for 37 to 60 months (adjusted relative risk, aRR = 9.15, 95% CI = 4.40–19.02). Females aged 12 to 35 years were at the greatest risk of endometriosis-associated uterine cancer (RR = 6.97, 95% CI = 3.41–14.26). In conclusion, patients with endometriosis were at great risk of uterine cancer, including endometrial cancer and uterine sarcoma, compared with propensity score-matched populations and compared with patients of PID. Younger females with endometriosis and patients who had endometriosis for three to five years were at the greatest risk of endometriosis-associated uterine cancer.