How novel genetic interactions evolve, under what selective pressures, and how they shape adaptive traits is often unknown. Here we uncover behavioural and developmental genetic mechanisms that enable water striders to survive attacks by bottom-striking predators. Long midlegs, critical for antipredator strategy, are shaped through a lineage-specific interaction between the Hox protein Ultrabithorax (Ubx) and a new target gene called gilt. The differences in leg morphologies are established through modulation of gilt differential expression between mid and hindlegs under Ubx control. Furthermore, short-legged water striders, generated through gilt RNAi knockdown, exhibit reduced performance in predation tests. Therefore, the evolution of the new Ubx-gilt interaction contributes to shaping the legs that enable water striders to dodge predator strikes. These data show how divergent selection, associated with novel prey-predator interactions, can favour the evolution of new genetic interactions and drive adaptive evolution.