Physical activity has been proposed to be beneficial for prevention of depression, although the importance of exercise intensity, sex-specific mechanisms, and duration of the effects need to be clarified. Using an observational study design, following 395,369 individuals up to 21 years we studied whether participation in an ultralong-distance cross-country ski race was associated with lower risk of developing depression. Skiers (participants in the race) and matched non-skiers from the general population (non-participants in the race) were studied after participation (same year for non-participation) in the race using the Swedish population and patient registries. The risk of depression in skiers (n = 197,685, median age 36 years, 38% women) was significantly lower, to nearly half of that in non-skiers (adjusted hazard ratio, HR 0.53) over the follow-up period. Further, a higher fitness level (measured as the finishing time to complete the race, a proxy for higher exercise dose) was associated with lower incidence of depression in men (adjusted HR 0.65), but not in women. Our results support the recommendations of engaging in physical activity as a preventive strategy decreasing the risk for depression in both men and women. Furthermore, the exercise could reduce risk for depression in a dose-dependent matter, in particular in males.