Many species of ants fall prey to pit-digging larval antlions (Myrmeleon spp.), extremely sedentary predators that wait, nearly motionless at the bottom of their pit traps, for prey to stumble inside. Previous research, both in the field and laboratory, has demonstrated a remarkable ability of these ants to rescue trapped nestmates, thus sabotaging antlions' attempts to capture them. Here we show that pavement ants, Tetramorium sp. E, an invasive species and a major threat to biodiversity, possess yet another, more effective, antipredator strategy, namely the ability to learn to avoid antlion traps following a single successful escape from a pit. More importantly, we show that this learned antipredator behavior, an example of natural aversive learning in insects, is more complicated than a single cue-to-consequence form of associative learning. That is, pavement ants were able to generalize, after one experience, from the learned characteristics of the pit and its specific location, to other pits and other contexts that differed in many features. Such generalization, often described as a lack of precise stimulus control, nonetheless would be especially adaptive in nature, enabling ants to negotiate antlions' pit fields, which contain a hundred or more pits within a few centimetres of one another. Indeed, the ability to generalize in exactly this way almost certainly is responsible for the sudden, and heretofore inexplicable, behavioural modifications of ants in response to an invasion of antlions in the vicinity of an ant colony.