Whether the relationships between ABO blood genotypes (AA, AO, BB, BO, AB, and OO) and dementia are modified by gender and APOE status has been unclear. We used data from the UK Biobank, a population-based cohort study of 487,425 individuals. Cox proportional hazards models were used to estimate hazard ratios (HRs) and 95% confidence intervals (CI) between ABO genotypes and risk of dementia. Multivariable linear regression models were used to estimate the relationship between ABO genotypes and MRI-based brain indices. Overall, 487,425 participants were included at baseline. After 34 million person-years follow up, 7,548 patients developed all-cause dementia. Before stratifying by sex and APOE status, compared to OO genotype, BB genotype was associated with increased risk of all-cause dementia (1.36, 1.03-1.80) and other types dementia (1.65, 1.20-2.28). After stratifying by sex, only in males, BB genotype was associated with higher risk of all-cause dementia (1.44, 1.02-2.09) and other types of dementia (1.95, 1.30-2.93). AB genotype in males was also associated with increased AD (1.34, 1.04-1.72). After further stratifying by APOE e4 status, BB genotype with two APOE e4 alleles showed even stronger association with all-cause dementia 4.29 (1.57, 11.72) and other types dementia (5.49, 1.70-17.69) in males. Also in males, AA genotype with one APOE e4 was associated with increased risks of all-cause dementia (1.27, 1.04-1.55), AD (1.45, 1.09-1.94) and other types dementia (1.40, 1.08-1.81). Linear regression models showed that in both sexes with APOE e4, AA genotype was associated with reduced total grey matter volume. Sex and APOE e4 carrier status modified the association between ABO genotypes and risk of dementia. In males, BB genotype was consistently associated with increased risk of dementia, especially in those with two APOE e4 alleles. Also, in males with one APOE e4, AA genotype might be linked to higher risk of dementia.