The immune system has an impact on the metabolic performance in vertebrates, thus the metabolic effects of immune cells are receiving intense attention today in the biomedical field. However, the evolutionary origin of the immunity-metabolism interaction is still uncertain. In this review, I show that mollusks and crustaceans integrate immune functions to a metabolic organ, the midintestinal gland ("hepatopancreas"). In these animals, the epithelial cells of the midintestinal gland are major sources of immune molecules, such as lectins, hemocyanin, ferritin, antibacterial and antiviral proteins, proteolytic enzymes and nitric oxide. There is crosstalk between midintestinal gland cells and phagocytes, which aids the initiation of the immune response and the clearance of pathogens. The midintestinal gland is thereby an integrated organ of immunity and metabolism. It is likely that immunity was the primary function of the midintestinal gland cells and that their role in the intermediate metabolism has evolved during the course of their further specialization.