Drosophila melanogaster larvae defend themselves against parasitoid attack via the process of encapsulation. However, flies that successfully defend themselves have reduced fitness as adults. Adults which carry an encapsulated parasitoid egg are smaller and females produce significantly fewer eggs than controls. Capsule-bearing males allowed repeated copulations with females do not show a reduction in their number of offspring, but those allowed to copulate only once did. No differences were found in time to first oviposition in females, or in time to first copulation in males. We interpret the results as arising from a trade-off between investing resources in factors promoting fecundity and mating success, and in defence against parasitism. The outcome of this investment decision influences the strength of selection for defence against parasitism.