Objective To test the hypotheses that physical activity in midlife is not associated with a reduced risk of dementia and that the preclinical phase of dementia is characterised by a decline in physical activity.Design Prospective cohort study with a mean follow-up of 27 years.Setting Civil service departments in London (Whitehall II study).Participants 10 308 participants aged 35-55 years at study inception (1985-88). Exposures included time spent in mild, moderate to vigorous, and total physical activity assessed seven times between 1985 and 2013 and categorised as "recommended" if duration of moderate to vigorous physical activity was 2.5 hours/week or more.Main outcome measures A battery of cognitive tests was administered up to four times from 1997 to 2013, and incident dementia cases (n=329) were identified through linkage to hospital, mental health services, and mortality registers until 2015.Results Mixed effects models showed no association between physical activity and subsequent 15 year cognitive decline. Similarly, Cox regression showed no association between physical activity and risk of dementia over an average 27 year follow-up (hazard ratio in the "recommended" physical activity category 1.00, 95% confidence interval 0.80 to 1.24). For trajectories of hours/week of total, mild, and moderate to vigorous physical activity in people with dementia compared with those without dementia (all others), no differences were observed between 28 and 10 years before diagnosis of dementia. However, physical activity in people with dementia began to decline up to nine years before diagnosis (difference in moderate to vigorous physical activity -0.39 hours/week; P=0.05), and the difference became more pronounced (-1.03 hours/week; P=0.005) at diagnosis.Conclusion This study found no evidence of a neuroprotective effect of physical activity. Previous findings showing a lower risk of dementia in physically active people may be attributable to reverse causation-that is, due to a decline in physical activity levels in the preclinical phase of dementia.