Vaccines stimulate the immune system by introducing antigens or weakened pathogens, prompting the body to produce a specific immune response. This prepares the immune system for future encounters, ensuring a rapid and effective response to the actual pathogen.