The association between kidney function and dementia risk and the mechanisms underlying this relationship remain unclear. Within the UK Biobank, 191 970 dementia-free participants aged ≥60 (mean age: 64.1 ± 2.9 years) were followed for 16 years to detect incident dementia. Serum creatinine and Cystatin C were measured at baseline to calculate estimated glomerular filtration rate (eGFR, mL/min/1.73 m2). Kidney function was categorized as normal (eGFR ≥ 90), mildly impaired (60 ≤ eGFR < 90), or moderately to severely impaired (eGFR < 60). Dementia was assessed based on self-reported medical history and medical records. During the follow-up, a subsample of 12 637 participants underwent brain MRI scans. Volumes of total brain, gray matter, white matter, hippocampus, and white matter hyperintensities were assessed. Over the follow-up, 5 327 (2.8%) participants developed dementia. Compared to normal kidney function, there was an increased risk of dementia with moderate to severely impaired kidney function (hazard ratio = 1.53, 95% confidence interval [CI]: 1.32-1.76) but not mildly impaired kidney function. In Laplace regression, dementia onset among people with moderate to severely impaired kidney function occurred 1.53 (95% CI: 0.98-2.08) years earlier than those with normal kidney function. Moderate to severely impaired kidney function was related to significantly lower gray matter volume (β = -0.11, 95% CI: -0.19 to -0.03), but not to other brain magnetic resonance imaging measures. Impaired kidney function is associated with about 50% increased risk of dementia and anticipates dementia onset by more than 1.5 years. Brain neurodegeneration may underlie the kidney function-dementia association.