The immune and circulatory systems of animals are functionally integrated. In mammals, the spleen and lymph nodes filter and destroy microbes circulating in the blood and lymph, respectively. In insects, immune cells that surround the heart valves (ostia), called periostial hemocytes, destroy pathogens in the areas of the body that experience the swiftest hemolymph (blood) flow. An infection recruits additional periostial hemocytes, amplifying heart-associated immune responses. Although the structural mechanics of periostial hemocyte aggregation have been defined, the genetic factors that regulate this process remain less understood. Here, we conducted RNAseq in the African malaria mosquito, Anopheles gambiae, and discovered that an infection upregulates multiple components of the IMD and JNK pathways in the heart with periostial hemocytes. This upregulation is greater in the heart with periostial hemocytes than in the circulating hemocytes or the entire abdomen. RNAi-based knockdown then showed that the IMD and JNK pathways drive periostial hemocyte aggregation and alter phagocytosis and melanization on the heart, thereby demonstrating how these pathways regulate the functional integration between the immune and circulatory systems. Understanding how insects fight infection lays the foundation for novel strategies that could protect beneficial insects and harm detrimental ones.