Pathogens have negative effects on the fitness of their hosts, reducing survival and/or decreasing their reproductive success. To cope with pathogen challenge, animals have developed a variety of defensive traits to evade parasite infection and minimize their detrimental effects. Uropygial gland secretion has been proposed to have antimicrobial and antifungal properties, which may potentially influence bird fitness. However, whether uropygial gland secretion may affect the breeding success of birds remains unknown. Here, we explore whether the relationship between uropygial gland volume and reproductive success could be determined by the abundance of conspecific barn swallows (Hirundo rustica), a small colonial migratory hirundine. Because a larger number of swallows nesting within the same building may boost abundance and transmission of pathogens, we predicted that the anti-pathogen properties of uropygial gland secretion may enhance bird reproductive success in environments with high density of conspecifics. We showed that barn swallows with larger uropygial glands had higher breeding success (greater total number of fledglings reared) when living in environments with higher abundance of conspecifics. In contrast, barn swallows with larger uropygial glands had lower reproductive success when breeding in environments with lower abundance of conspecifics. Furthermore, we found that the same individuals did not modify uropygial glands in response to different pathogen pressure experienced across consecutive years. These outcomes suggest that benefits of uropygial secretion are host density dependent, thus consistent with this being a heritable trait that has evolved as a consequence of divergent selection imposed by pathogens. To face pathogen challenges, animals have evolved a broad range of barriers and defense mechanisms to avoid parasite infection and/or to minimize negative effects. Uropygial gland secretion has been proposed to have antimicrobial and antifungal properties, but also act as a defensive mechanism against malaria infection. However, whether uropygial gland secretions may affect the reproductive success of birds remains poorly studied. In this study, we explore, for the first time, whether the relationship between uropygial gland volume and reproductive success could be determined by the abundance of conspecifics. We found that barn swallows with larger uropygial glands had higher breeding success when living in environments with higher abundance of conspecifics. Because a larger number of swallows nesting within the same building may boost abundance and transmission of pathogens, this novel outcome is consistent with a heritable trait that has evolved as a consequence of divergent selection imposed by pathogens.