Developing an effective stroke prevention strategy is crucial for elderly atrial fibrillation (AF) patients with dementia. This is due to the limited and inconsistent evidence available on this topic. In this nationwide, population-based cohort study, we aim to compare the effectiveness and safety of direct oral anticoagulants (DOACs) and warfarin in AF patients with dementia. We identified AF patients with dementia, aged 50 years or older, from Taiwan's National Health Insurance Research Database between 2010 and 2019. The primary outcome was a composite of hospitalizations due to ischemic stroke, acute myocardial infarction, intracranial hemorrhage, or major bleeding, as well as all-cause mortality. We used 1:1 propensity score matching and Cox proportional hazard models to adjust for confounding factors when comparing outcomes between warfarin and DOAC (apixaban, dabigatran, edoxaban, or rivaroxaban) users or warfarin and each individual DOAC. There were 2952 patients in the DOAC-warfarin matched cohort. The apixaban-, dabigatran-, edoxaban-, and rivaroxaban-warfarin matched cohorts had 2346, 2554, 1684, and 2938 patients, respectively. The DOAC group, when compared to warfarin, was associated with a lower risk of both the composite outcome (hazard ratio (HR), 0.81; 95% confidence interval (CI) 0.69-0.95) and ischemic stroke (HR 0.65; 95% CI 0.48-0.87). Apixaban (HR 0.79; 95% CI 0.66-0.94), dabigatran (HR 0.64; 95% CI 0.53-0.77), and rivaroxaban (HR 0.82; 95% CI 0.70-0.97) were also associated with a lower risk of the composite outcome. Compared to warfarin, DOACs, whether as a group or apixaban, dabigatran, or rivaroxaban individually, were associated with a reduced risk of the composite outcome in elderly patients with concurrent AF and dementia.