Migratory insect pests tend to suddenly immigrate into new habitats over a short period to simultaneously lay eggs in clusters, resulting in gregarious larvae that cause severe damage to crops. These aggregated larvae can adapt well to various natural enemies and pathogens in their new habitats, but how their resistance might be enhanced and its immunological significance remain unknown. Here, we examined how infection by a pathogen and a parasitic fly affect the immune response and migratory behavior in two phases of the oriental armyworm, Mythimna separata, which differ dramatically in their flight capacity and fecundity. The gregarious larvae displayed greater resistance than solitary larvae to the challenges of both the entomopathogenic fungus Metarhizium anisopliae and the parasitoid Exorista civilis. In response to a challenge by M. anisopliae, gregarious larvae exhibited more pronounced increases in phenoloxidase (PO) activity and lysozyme activity than solitary larvae. Furthermore, in addition to the greater PO and lysozyme activities, the levels of dopamine and 5-hydroxytryptamine (5-HT) were also greater in challenged gregarious and solitary larvae. Injection of dopamine (or 5-HT) significantly enhanced PO activity, lysozyme activity, antibacterial activity and larval survival. Subsequently, there was a significant increase in the flight capacity of adults derived from gregarious larvae challenged by M. anisopliae; while no significant variation was observed in the adults from challenged solitary larvae. The preoviposition period, oviposition period and fecundity were not significantly affected by M. anisopliae, regardless of whether the larvae were gregarious or solitary. These results provide new insights into the relationship between migration and immunity in insects, and their behavior after immunization.