Immunocompetence (i.e., the ability to produce an immune response to pathogens) can be predicted to influence the chances that organisms have to survive and reproduce. In this study we simulated a challenge to the immune systems of male barn swallows (Hirundo rustica) by injecting them intraperitoneally with a multigenic antigen, sheep red blood cells, and we analyzed long-term survival in relation to their immunocompetence. Males were assigned to four groups that differed for the treatment of the length of the outermost tail feathers, a sexually dimorphic ornamental character that is currently under directional sexual selection. Immunocompetence was measured as change of concentration of gamma globulins relative to plasma proteins. The intensity of the immune response was independent of age. Males that showed the highest short-term response to sheep red blood cells were more likely to survive until the breeding season following that in which they had been inoculated, a pattern consistently observed within each experimental group. Males with comparatively long tails were more likely to survive than those with short tails. To our knowledge, the results of this study are the first to demonstrate that immunocompetence can predict long-term survival in a free-ranging vertebrate. Moreover, they are compatible with current models of parasite-mediated sexual selection because long-tailed males are more immunocompetent than short-tailed ones, and females, by preferring to mate with the most ornamented males, may acquire the “good genes” for high immunocompetence and, hence, for high viability of their offspring.