The root causes of dementia are still largely unclear, and the medical community lacks highly effective preventive and therapeutic pharmaceutical agents for dementia despite large investments into their development. There is growing interest in the question if infectious agents play a role in the development of dementia, with herpesviruses attracting particular attention. To provide causal as opposed to merely correlational evidence on this question, we take advantage of the fact that in Wales eligibility for the herpes zoster vaccine (Zostavax) for shingles prevention was determined based on an individual9s exact date of birth. Those born before September 2 1933 were ineligible and remained ineligible for life, while those born on or after September 2 1933 were eligible to receive the vaccine. By using country-wide data on all vaccinations received, primary and secondary care encounters, death certificates, and patients9 date of birth in weeks, we first show that the percentage of adults who received the vaccine increased from 0.01% among patients who were merely one week too old to be eligible, to 47.2% among those who were just one week younger. Apart from this large difference in the probability of ever receiving the herpes zoster vaccine, there is no plausible reason why those born just one week prior to September 2 1933 should differ systematically from those born one week later. We demonstrate this empirically by showing that there were no systematic differences (e.g., in pre-existing conditions or uptake of other preventive interventions) between adults across the date-of-birth eligibility cutoff, and that there were no other interventions that used the exact same date-of-birth eligibility cutoff as was used for the herpes zoster vaccine program. This unique natural randomization, thus, allows for robust causal, rather than correlational, effect estimation. We first replicate the vaccine9s known effect from clinical trials of reducing the occurrence of shingles. We then show that receiving the herpes zoster vaccine reduced the probability of a new dementia diagnosis over a follow-up period of seven years by 3.5 percentage points (95% CI: 0.6 - 7.1, p=0.019), corresponding to a 19.9% relative reduction in the occurrence of dementia. Besides preventing shingles and dementia, the herpes zoster vaccine had no effects on any other common causes of morbidity and mortality. In exploratory analyses, we find that the protective effects from the vaccine for dementia are far stronger among women than men. Randomized trials are needed to determine the optimal population groups and time interval for administration of the herpes zoster vaccine to prevent or delay dementia, as well as to quantify the magnitude of the causal effect when more precise measures of cognition are used. Our findings strongly suggest an important role of the varicella zoster virus in the etiology of dementia.