Every pathogen has molecules on its surface called antigens. These are different for each type of pathogen. When a pathogen gets into the body, lymphocytes that can respond to its antigens are stimulated, and they begin to make antibodies.
An antibody has a shape that fits the antigen on one particular pathogen, so antibodies are specific. Antibodies bind to the antigens and make the pathogens clump together. This makes it easier for phagocytes to engulf and destroy them. Lymphocytes can also make antitoxins, which neutralise the toxins that some pathogens release.
After the infection, some lymphocytes stay in the blood as memory cells. If the same pathogen enters again, the memory cells make the right antibodies much faster and in larger amounts. The pathogen is destroyed before it can make the person ill, so the person is immune to that disease.