Although an increase in competition is a common cost associated with intraspecific crowding, spatial aggregation across food-limited resource patches is a widespread phenomenon in many insect communities. Because intraspecific aggregation of competing insect larvae across, e.show $132#g. fruits, dung, mushrooms etc., is an important means by which many species can coexist (aggregation model of species coexistence), there is a strong need to explore the mechanisms that contribute to the maintenance of this kind of spatial resource exploitation. In the present study, by using Drosophila-parasitoid interactions as a model system, we tested the hypothesis whether intraspecific aggregation reflects an adaptive response to natural enemies. Most of the studies that have hitherto been carried out on Drosophila-parasitoid interactions used an almost two-dimensional artificial host environment, where host larvae could not escape from parasitoid attacks, and have demonstrated positive density-dependent parasitism risk. To test whether these studies captured the essence of such interactions, we used natural breeding substrates (decaying fruits). In a first step, we analysed the parasitism risk of Drosophila larvae on a three-dimensional substrate in natural fly communities in the field, and found that the risk of parasitism decreased with increasing host larval density (inverse density dependence). In a second step, we analysed the parasitism risk of Drosophila subobscura larvae on three breeding substrate types exposed to the larval parasitoids Asobara tabida and Leptopilina heterotoma. We found direct density-dependent parasitism on decaying sloes, inverse density dependence on plums, and a hump-shaped relationship between fly larval density and parasitism risk on crab apples. On crab apples and plums, fly larvae benefited from a density-dependent refuge against the parasitoids. While the proportion of larvae feeding within the fruit tissues increased with larval density, larvae within the fruit tissues were increasingly less likely to become victims of parasitoids than those exposed at the fruit surface. This suggests a facilitating effect of group-feeding larvae on reaching the spatial refuge. We conclude that spatial aggregation in Drosophila communities can at least in part be explained as a predator avoidance strategy, whereby natural enemies act as selective agents maintaining spatial patterns of resource utilisation in their host communities.