Both diabetes mellitus (DM) and cancer are common diseases and they frequently occur in the same patients. We investigated the all-cause and cause-specific mortality dynamics in relation to baseline DM, statin use and metformin use. The study population consisted of 39,900 incident cancer cases from Finland, 19,822 patients were free of DM at the start of follow-up and 20,078 had DM. Mortality from all causes, and cancer, cardiovascular (CVD) and other causes was analysed using Poisson regression model with the following variables: sex, age, DM, statin and metformin usage in baseline, cancer type and stage and calendar period. Statin usage was associated with a reduced cancer-specific mortality with incidence rate ratio (IRR) 0.72 (95% confidence interval 0.69-0.74), IRR for CVD mortality was 0.95 (0.88-1.02) and for other causes 0.64 (0.56-0.74). In a sub-population of DM patients, IRR for metformin in all-cause mortality was 0.74 (0.71-0.78), in cancer mortality 0.75 (0.72-0.79), in CVD mortality 0.75 (0.68-0.83) and other causes 0.68 (0.60-0.78). In conclusion, our register-based study of survival after cancer diagnosis showed that patients with diabetes had substantially poorer outcome in all measures. An association between baseline statin usage and lower all-cause, cancer and cardiovascular mortality was modified by cancer type. The effect of statin use was largest for breast and colorectal cancer. Metformin usage in a subpopulation of oral antidiabetic users was in general associated with lower mortality, but this association was modified by cancer type. The association was strongest for liver, colorectal and breast cancer.