Objectives To investigate, in a prospective cohort study, the association between cognitive impairment and cardiovascular disease (CVD), to quantify the extent to which uncontrolled risk factors mediate this association, and to explore whether the mediation effect varies across sex and age groups. Design Prospective cohort study. Setting UK Biobank, a large population-based cohort study in the UK. Participants A total of 152 155 participants without prevalent CVD or dementia at baseline were included. The mean age was 56.3±8.2 years, and 44.0% were male. Primary outcomes Cardiovascular death and composite cardiovascular outcomes, assessed using Cox proportional-hazards models and mediation analyses. Results During a median follow-up of 13.03–13.87 years, 1474 cardiovascular deaths and 21 518 composite cardiovascular outcomes were recorded. Participants with cognitive impairment (n=23 146; 15.2%) exhibited higher proportions of lifestyle, metabolic and psychological risks (p<0.001), except alcohol consumption. Cognitive impairment was associated with a 21% increased risk of cardiovascular death (HR 1.21, 95% CI 1.07 to 1.37) and a 5% higher risk of composite cardiovascular outcomes (HR 1.05, 95% CI 1.01 to 1.09). Mediation analyses indicated that 11.30%, 9.10% and 8.25% of the association between cognitive impairment and cardiovascular death were mediated by uncontrolled glucose, alcohol consumption and depression, respectively. Similarly, 17.50%, 12.39% and 11.98% of the association with composite cardiovascular outcomes were mediated by depression, anxiety and alcohol consumption, respectively. These mediating effects varied by sex and were more pronounced in females. Conclusions Cognitive impairment is associated with increased risks of cardiovascular death and composite cardiovascular outcomes. Uncontrolled lifestyle, cardiometabolic and psychological risk factors partially mediate this association, highlighting the importance of comprehensive management to improve cardiovascular prognosis in this population.