Mechanisms of recognition are essential to the evolution of mutualistic and parasitic interactions between species. One such example is the larval mimicry that Maculinea butterfly caterpillars use to parasitize Myrmica ant colonies. We found that the greater the match between the surface chemistry of Maculinea alcon and two of its host Myrmica species, the more easily ant colonies were exploited. The geographic patterns of surface chemistry indicate an ongoing coevolutionary arms race between the butterflies and Myrmica rubra, which has significant genetic differentiation between populations, but not between the butterflies and a second, sympatric host, Myrmica ruginodis, which has panmictic populations. Alternative hosts may therefore provide an evolutionary refuge for a parasite during periods of counteradaptation by their preferred hosts.