Sunlight is one source of vitamin D
Vitamin D, found in fish and produced by sun exposure, can help stave off the mental decline that can affect people in old age, a study has suggested.
UK and US researchers looked at 2,000 people aged 65 and over.
They found that compared to those with the highest vitamin D levels, those with the lowest were more than twice as likely to have impaired understanding.
Alzheimer's charities said the research was interesting, but more work was needed to understand vitamin D's role.
Vitamin D is important in maintaining bone health, in the absorption of calcium and phosphorus, and in helping the immune system.
The body makes vitamin D when it is exposed to the sun, or it can be obtained from foods such as oily fish, and those fortified with vitamin D, such as milk, cereals, and soya drinks.
But older people's skin is less able to absorb vitamin D from sunlight so they are more reliant on obtaining it from other sources.
Animal and lab studies have previously suggested that the vitamin can have a beneficial effect on cognitive function.
The team from the Peninsula Medical School in Exeter, the University of Cambridge and the University of Michigan, assessed people's cognition, or comprehension skills.
People who have impaired cognitive function are more likely to develop dementia.
The researchers looked at people who had taken part in the Health Survey for England in 2000.
Just over 200 had significant cognitive impairment, assessed by looking at people's attention, orientation in time and space and memory.
The study found that as levels of vitamin D went down, levels of cognitive impairment went up.
The paper will appear in a forthcoming issue of the Journal of Geriatric Psychology and Neurology.
Dr Iain Lang from the Peninsula Medical School, who worked on the study, said: "For those of us who live in countries where there are dark winters without much sunlight, like the UK, getting enough vitamin D can be a real problem - particularly for older people, who absorb less vitamin D from sunlight.
"One way to address this might be to provide older adults with vitamin D supplements.
"This has been proposed in the past as a way of improving bone health in older people, but our results suggest it might also have other benefits.
"We need to investigate whether vitamin D supplementation is a cost-effective and low-risk way of reducing older people's risks of developing cognitive impairment and dementia."
Rebecca Wood, chief executive of the Alzheimer's Research Trust, said: "Many foods that contain vitamin D, such as oily fish, eggs and breakfast cereals, are also good sources of vitamin B12, which, as previous studies have shown, can help protect the brain.
"Diet is known to influence dementia risk. The best way of reducing your risk of developing dementia is to maintain a balanced diet with regular exercise and frequent social interactions."
She added: "These findings may be significant, but much more research is needed."
Dr Susanne Sorensen, head of research at the Alzheimer's Society, added: "One in three people over 65 will die with dementia so research into how we can reduce risk is to be encouraged.
"There was some previous evidence to suggest that people with dementia may have a lower level of vitamin D in their blood but it was not clear if this happened after the onset of disease.
"It would be interesting if a low level of vitamin D was found to be a risk factor for cognitive problems as it is cheap and easy to remedy.
"We look forward to seeing the published results of this new research to help us better understand the potential role of vitamin D in reducing risk."