We counted the numbers of pupae of two ectoparasitic flies (Protocalliphora sp. and Ornithomyia sp.) in the nests of a passerine bird, the pied flycatcher (Ficedula hypoleuca) to find out if their prevalence or intensity are affected by long-term environmental pollution by a copper smelter and whether such an interaction would have impacts on birds' breeding success. Fecal metal concentrations of F. hypoleuca nestlings were used to explore direct association between metal levels and parasite prevalence, but we also included other explanatory factors in our analysis, such as timing of breeding, brood size, ambient temperature, habitat quality and host population density. We found that environmental pollution decreased the prevalence of Protocalliphora via changed habitat quality but did not affect the prevalence of Ornithomyia. The prevalence of neither ectoparasite was, however, directly related to ambient metal levels. Both ectoparasites showed higher prevalence when ambient temperature during the nestling period was high, emphasizing the potential of climate change to modify host–parasite relationships. The prevalence of Ornithomyia was further highest in dense F. hypoleuca populations and late broods. Nestling survival decreased with increasing infestation intensity of Ornithomyia while no association was found for Protocalliphora. Despite relatively low numbers and overall weak effect of parasites on survival, the possible delayed and/or sublethal effects of these ectoparasites call for further studies. Our results suggest that pollution-related effects on avian ectoparasite numbers are species-specific and reflect habitat changes rather than direct toxic effect of heavy metals.