A highly specific defensive reaction of the body to invasion by a foreign substance or organism; consists of a primary response in which the invader is recognized as foreign, or "not-self," and eliminated and a secondary response to subsequent attacks by the same invader. Mediated by two types of lymphocytes B cells, which mature in the bone marrow and are responsible for antibody production, and T cells, which mature in the thymus and are responsible for cell-mediated immunity.