431,699 participants with a mean of 8.65 (standard deviation [SD] 2.61) years of follow-up were included; 5,542 all-cause dementia (ACD) cases were documented. We observed that per SD decreases in alanine transaminase (ALT; hazard ratio [HR], 0.917; PFDR < 0.001) and per SD increases in aspartate aminotransferase (AST; HR, 1.048; PFDR = 0.010), AST/ALT (HR, 1.195; PFDR < 0.001), gamma-glutamyl transpeptidase (GGT; HR, 1.066; PFDR < 0.001), alcoholic liver disease (ALD; HR, 2.872; PFDR < 0.001), fibrosis and cirrhosis of liver (HR, 2.285; PFDR = 0.002), and metabolic dysfunction-associated steatotic liver disease (MASLD; HR, 2.862; PFDR < 0.001), being significantly associated with a higher risk of incident ACD. Restricted cubic spline models identified strong U-shaped associations between Alb and AST and incident ACD (Pnon-linear < 0.05). Worse cognition was positively correlated with AST, AST/ALT, direct bilirubin (DBil), and GGT; negatively correlated with ALT, Alb, and total bilirubin (TBil); and ALD and fibrosis and cirrhosis of liver (PFDR < 0.05). Moreover, changes in ALT, GGT, AST/ALT, ALD, and MASLD were significantly associated with altered cortical and subcortical regions, including hippocampus, amygdala, thalamus, pallidum, and fusiform (PFDR < 0.05).