Background: Bacterial pneumonia is associated with an increased risk of dementia. However, the association between different pathogens of bacterial pneumonia and the risk of dementia remains unclear. Methods: Using the Taiwan National Health Insurance Research Database, we recruited 11,712 patients with bacterial pneumonia and 11,120 controls between 1997 and 2012 and followed them up until the end of 2013. A diagnosis of dementia, Alzheimer's disease (AD), vascular dementia (VaD), and unspecified dementia were identified during the follow-up period. Cox regression analyses were performed with adjustments for confounders. Sensitivity analysis was conducted to exclude patients with prodromal dementia. Results: Patients with bacterial pneumonia were more likely to develop dementia (hazard ratio [HR]: 2.83, 95% confidence interval [CI]: 2.53–3.18), AD (HR: 2.44, 95% CI: 1.65–3.61), VaD (HR: 4.15, 95% CI: 3.20–5.38), and unspecified dementia (HR: 2.62, 95% CI: 2.29–3.00) compared with controls after adjusting for potential confounders. Subgroup pathogen analyses showed that the HR of AD was 3.85 (1.66–8.96) for Hemophilus, and the HR of VaD was 5.40 for Staphylococcus. The risks of dementia and VaD were associated with repeated hospitalization due to bacterial pneumonia in a dose-dependent manner. Sensitivity analyses after exclusion of the first three years or first five years of observation and after exclusion case enrollment before 2010 or 2008 showed consistent findings. Conclusion: Different pathogens are associated with different risks of AD, VaD, and unspecified dementia. Further studies are necessary to investigate the underlying mechanisms of bacterial pneumonia and dementia.