Pupation site-seeking larvae of the codling moth, Cydia pomonella, aggregate in response to aggregation pheromone produced by cocoon-spinning conspecific larvae. Larvae that pupate in an aggregation rather than in solitude may experience a lower rate of parasitism by the parasitoid Mastrus ridibundus. Additionally, adults eclosing from a larval aggregation may encounter mates more rapidly at the site of eclosion (on-site) than away from that site (off-site). We employed an evolutionary simulation to determine the effect of several ecological parameters on the evolution of larval aggregation behavior. These parameters included (i) the probability of mate encounter off-site; (ii) the time available for finding a mate; and (iii) the population density of parasitoids and their rate of larval parasitism. The model predicts that larval aggregation behavior is selected for when the probability of off-site mate encounter is low, the time to locate mates is short, and egg-limited parasitoids are at high population levels. We also show that aggregations reduce the risk of parasitism through dilution effects. The parameters found to favour the evolution of larval aggregation behavior are consistent with life history traits exhibited by C. pomonella.