Major depression is an evolutionary paradox: it carries great disadvantages for survival and reproduction of both patients and their relatives, yet it is common and has significant heritability. We propose a new hypothesis to help explain many of depression's symptoms and its risk factors, most of them not explained by previous evolutionary theories. We hypothesize that the evolutionary costs of depression are offset by its benefits in combating existing infections and avoiding new ones. As our hypothesis predicts, depression can be elicited by various infections as well as by environmental stressors that compromise immune function. Moreover, many depressive symptoms tend to aid immune function and reduce exposure to new infections and stressors. The hypothesis makes many predictions about the epidemiology and physiology of depression that are supported by available evidence. The hypothesis also suggests that possible underlying infectious and immune factors deserve greater consideration in prevention and treatment of depression.