Sociality is associated with increased risks of parasitism, predation, and social competition, which may interact because social stress can reduce immunity, and parasitized individuals are more likely to fall prey to a predator. A mechanism allowing evolution of sociality in spite of high costs of parasitism is increased investment in antiparasite defenses. Here we show that the impact of parasites on host reproductive success was positively associated with the degree of sociality in the bird family Hirundinidae. However, the cost of parasitism in highly colonial species was countered by high levels of T- and B-cell immune responses. Investment in immune function among colonial species was particularly strong in nestlings, and among social species, this investment was associated with a relatively prolonged period of development, thereby leading to extended exposure to parasites. Thus, highly social species such as certain species of swallows and martins may cope with strong natural selection arising from parasites by heavy investment in immune function at the cost of a long exposure to nest parasites.