This retrospective cohort study aimed to examine the relationship between herpes zoster ophthalmicus (HZO) and the subsequent risk of dementia using a population-based database. We retrieved the study sample from the Taiwan Longitudinal Health Insurance Database 2005. The study group included 846 patients with HZO, and the comparison group included 2538 patients without HZO. Each patient was individually followed for a 5-year period to identify those patients who subsequently received a diagnosis of dementia. We performed a Cox proportional hazards regression to calculate the hazard ratios (HRs) along with 95% confidence intervals (CIs) for dementia during the follow-up period between patients with HZO and comparison patients. The respective incidence rates of dementia per 1000 person-years were 10.15 (95% CI: 7.22~13.87) and 3.61 (95% CI: 2.61~4.89) for patients with HZO and comparison patients. The Cox proportional analysis showed that the crude HR of dementia during the 5-year follow-up period was 2.83 (95% CI: 1.83-4.37) for patients with HZO than comparison patients. After adjusting for patients' characteristics and comorbidities, HZO patients were still at a 2.97-fold greater risk than comparison patients for developing dementia. Furthermore, we found that of sampled male patients, the crude HR of dementia for patients with HZO was as high as 3.35 (95% CI = 1.79-6.28) compared to comparison patients. This study demonstrated an association between HZO and dementia. Clinicians must be alert to suspect dementia in patients with cognitive impairment who had prior HZO.