Objective: Depression has been linked to excess mortality in individuals with type 2 diabetes, but it remains unclear what drives this association. We examined if the association depends on unhealthy lifestyle and medical comorbidity. Methods: We followed a clinically recruited cohort of Danish people with type 2 diabetes (n = 8175) with fine-grained clinical information and a population-wide register-based cohort of Danish individuals with HbA1c-defined type 2 diabetes (n = 87 500) representing everyday clinical practice. Antidepressant drug use prior to the onset of type 2 diabetes was used as a proxy for preexisting depression. In both cohorts, we first estimated the association between depression and 5-year mortality following type 2 diabetes, using a Cox proportional hazards model, yielding sex- and age-adjusted mortality rate ratios (MRRs). We subsequently examined how further adjustment for markers of unhealthy lifestyle (smoking, physical inactivity, obesity, alcohol abuse, and marital status) and medical comorbidity affected the association. Results: Preexisting depression was associated with an approximately 50% increased age- and sex-adjusted all-cause mortality rate in both the clinically recruited- (5-year MRR: 1.46; 95% CI: 1.12-1.90) and the register-based type 2 diabetes cohort (5-year MRR: 1.51; 95% CI: 1.45-1.57). The excess mortality associated with depression almost disappeared when the analyses were adjusted for unhealthy lifestyle and medical comorbidity in both the clinically recruited- (MRR: 1.05; 95% CI: 0.72-1.52) and the register-based type 2 diabetes cohort (MRR: 1.14, 95% CI: 1.09-1.19). Conclusions: A large fraction of the excess mortality associated with preexisting depression in type 2 diabetes is attributable to the unhealthy lifestyle and medical comorbidity accompanying depression.