Herd immunity exists and it is well documented. In fact, there is a brilliant animation created by the Harvard Medical School that explains this process.
Vaccinations help prime your body to fight off a specific infection. However, it usually takes a few weeks for your body to create a reserve of immune cells for when you next encounter the infection again. Therefore, if you were infected just before or after receiving the vaccine, you might still get sick because the vaccine did not have ample time to provide any protection.