IMPORTANCE A bidirectional relationship exists between epilepsy and depression. However, any putative biological gradient between depression severity and the risk of epilepsy, and the degree to which depression mediates the influence of independent risk factors for epilepsy, has yet to be examined. OBJECTIVE To determine the effect of depression on the risk of epilepsy and seizure outcomes. DESIGN, SETTING, AND PARTICIPANTS An observational study of a population-based primary care cohort (all patients free of prevalent depression and epilepsy at 18-90 years of age who were active after the Acceptable Mortality Reporting date in The Health Improvement Network database) and a prospectively collected tertiary care cohort (all patients whose data were prospectively collected from the Calgary Comprehensive Epilepsy Programme). The analyses were performed on March 16, 2016. MAIN OUTCOME AND MEASURES The hazard of developing epilepsy after incident depression and vice versa was calculated. In addition, a mediation analysis of the effect of depression on risk factors for epilepsy and the odds of seizure freedom stratified by the presence of depression were performed. RESULTS We identified 10 595 709 patients in The Health Improvement Network of whom 229 164 (2.2%) developed depression and 97 177 (0.9%) developed epilepsy. The median age was 44 years (interquartile range, 32-58 years) for those with depression and 56 years (interquartile range, 43-71 years) for those with epilepsy. Significantly more patients with depression (144 373 [63%] were women, and 84 791 [37%] were men; P < .001) or epilepsy (54 419 [56%] were women, and 42 758 [44%] were men; P < .001) were female. Incident epilepsy was associated with an increased hazard of developing depression (hazard ratio [HR], 2.04 [95%CI, 1.97-2.09]; P < .001), and incident depression was associated with an increased hazard of developing epilepsy (HR, 2.55 [95%CI, 2.49-2.60]; P < .001) There was an incremental hazard according to depression treatment type with lowest risk for those receiving counselling alone (HR, 1.84 [95%CI, 1.30-2.59]; P < .001), an intermediate risk for those receiving antidepressants alone (HR, 3.43 [95%CI, 3.37-3.47]; P < .001), and the highest risk for those receiving both (HR, 9.85 [95%CI, 5.74-16.90]; P < .001). Furthermore, depression mediated the relationship between sex, social deprivation, and Charlson Comorbidity Index with incident epilepsy, accounting for 4.6%, 7.1%, and 20.6%of the total effects of these explanatory variables, respectively. In the Comprehensive Epilepsy Programme, the odds of failing to achieve 1-year seizure freedom were significantly higher for those with depression or treated depression. CONCLUSIONS AND RELEVANCE Common underlying pathophysiological mechanisms may explain the risk of developing epilepsy following incident depression. Treated depression is associated with worse epilepsy outcomes, suggesting that this may be a surrogate for more severe depression and that severity of depression is associated with severity of epilepsy.