Objective To explore the relationship between diabetes and cancer.Design The Fremantle Diabetes Study (FDS) was a community-based longitudinal observational study of 1426 subjects, 1294 of which had type 2 diabetes.Methods The FDS type 2 cohort and four age-, sex- and postcode-matched controls per case were followed for cancer events from 1993 until mid-2010 and incidence rate ratios (IRRs) were calculated. Competing risks proportional hazards models generated risk factors for incident cancers in the diabetic group.Results There were 309 first cancers over 13 051 patient-years, or 2368 (95% confidence interval (95% CI) 2111–2647)/100 000 patient-years in the diabetes patients vs 1131 over 60 324 patient-years (1875 (1769–1987)/100 000 patient-years) in the controls. For those aged ≥45 years, the risk of all-cause cancer was elevated in type 2 diabetic men (IRRs 1.23, 95% CI 1.04–1.45) and women (1.30, 1.06–1.59). The incidence of colorectal cancer was increased (1.36, 1.01–1.82), especially in diabetic men aged 75–84 years (2.14, 1.22–3.64). Age at diabetes diagnosis (sub-hazard ratio 1.05, 1.02–1.09), calcium channel blocker therapy (2.37, 1.39–4.06), recent exercise (2.11, 1.06–4.20) and serum total cholesterol (0.68, 0.52–0.88) increased colorectal cancer risk. Pancreatic cancer was also more frequent in the diabetic patients (IRR 2.26, 1.20–4.10). Diabetic men and women had similar risks of prostate and breast cancer to those of controls (0.83, 0.59–1.14 and 0.86, 0.52–1.36). Conclusions Type 2 diabetes is associated with a moderately increased cancer risk in well-characterised community-based patients, especially pancreatic cancer and colorectal cancer in older men. Recommended cancer screening should be considered as part of routine diabetes management.