Despite the ubiquity of ontogenetic niche shifts, their drivers and consequences are poorly understood. Different nutritional requirements and stage-specific physiological limitations have often been offered as explanations for these life history features, but emerging work has demonstrated that top-down factors may also be important. We studied the roles of predation and associational refuge in ontogenetic niche shifts for a holometabolous insect (Platyprepia virginalis), which shifts habitats and host plants to pupate. We examined the effect of pupation site selection across habitats and host plants by late-instar caterpillars on the rate of predation during the relatively vulnerable pupal stage. Studying the ontogenetic transition from mobile caterpillar to non-feeding, sessile pupa allows isolation of top-down effects from bottom-up, nutritional effects. An observational study supported previous findings that feeding caterpillars preferred marsh habitats, but pupating caterpillars preferred prairie habitats. Experiments demonstrated that caterpillars preferred to pupate within a physically defended plant species. Pupation within this defended plant species resulted in reduced predation (an associational refuge), and removal of the physical defense structures negated the reduced-predation effect. This experiment shows that ontogenetic niche shifts can be driven by predation and can involve facilitation by a host plant that provides a refuge to predation. The co-option of plant chemical defenses by animals is widely established. However, finding a clear example in which an animal exploits a plant's physical defense is rare, especially in the context of ontogenetic niche shifts. This work shows that facilitation mediated by refuge from predation provided by host plants and life-stage-dependent predation risk can interact to shape species' distributions.