A vaccine puts into the body weakened/dead pathogenic material, which by itself is incapable of causing disease. How does this help to protect the body in the case of infection by a live pathogen?
It shows your body what the pathogen looks like chemically, so it can learn how to identify it and destroy it without you becoming sick. So if you actually do get sick later from same strain of pathogen in the vaccine your body already knows how to fight it so you will not be sick as long or at all.