Objective: To quantify cancer risk in opioid dependence and the association with infection by the oncogenic blood-borne viruses (BBVs) hepatitis C (HCV), hepatitis B (HBV) and HIV. Design: Cohort study. Setting: New South Wales, Australia. Participants: All 45 412 adults aged 16 years or over registered for opioid substitution therapy (OST) between 1985 and 2007. Notifications of cancer, death and infection with HCV, HBV and HIV were ascertained by record linkage with registries. Main outcome measures: The ratios of observed to expected number of cancers, standardised incidence ratios (SIRs), and the average annual per cent change (AAPC) in overall age and sex-standardised cancer incidence. Results: Overall cancer risk was modestly increased compared to the general population (SIR 1.15, 95% CI 1.07 to 1.23). Excess risk was observed for 11 cancers, particularly lung (4.02, 95% CI 3.32 to 4.82), non-Hodgkin's lymphoma (1.51, 95% CI 1.20 to 1.88) and liver (8.04, 95% CI 6.18 to 10.3). Reduced risk was observed for six cancers, including prostate (0.16, 95% CI 0.06 to 0.32) and breast (0.48, 95% CI 0.35 to 0.62). Individuals notified with HCV or HBV had a markedly increased risk of liver cancer; lung cancer risk was also increased in those with HCV. HIV was associated with an elevated risk of liver, anus and kidney cancer, non-Hodgkin lymphoma and Kaposi sarcoma. Cancer risk was not increased in individuals without a BBV notification, apart from pancreatic cancer (3.92, 95% CI 1.07 to 10.0). Cancer incidence increased significantly over time (AAPC 9.4%, 4.2% to 15%, p=0.001). Conclusions: BBVs play a major role in the cancer risk profile of opioid-dependent individuals registered for OST. To address the dramatic increasing trend in cancer incidence, the OST setting could be utilised for cancer prevention strategies.