Roasting coffee beans triggers the release of phenylindanes, a group of compounds which prevent the "clumping" of proteins common in Alzheimer's and Parkinson's.
Alzheimer's develops when these proteins, beta amyloid and tau, clump together between neurons.
Study lead Dr Donald Weaver, co-director of the Krembil Brain Institute in Canada, said: "Coffee consumption does seem to have some correlation to a decreased risk of developing Alzheimer's disease and Parkinson's disease.
"But we wanted to investigate why that is, which compounds are involved and how they may impact age-related cognitive decline.
"The caffeinated and decaffeinated dark roast both had identical potencies in our initial experimental tests.
"So we observed early on that its protective effect could not be due to caffeine."
Dr Weaver, with his co-researchers Dr Ross Mancini and Dr Yanfei Wang, tested phenylindanes levels in light roast, dark roast and decaffeinated dark roast coffees.
They discovered levels of the chemical - and the degree of protection - increased the more the coffee was roasted.
Dr Weaver said: "So phenylindanes are a dual-inhibitor. Very interesting, we were not expecting that."
Dr Mancini added: "It's the first time anybody's investigated how phenylindanes interact with the proteins that are responsible for Alzheimer's and Parkinson's.
"The next step would be to investigate how beneficial these compounds are, and whether they have the ability to enter the bloodstream, or cross the blood-brain barrier.
"The fact that it's a natural compound versus synthetic is also a major advantage," said Dr Weaver.
He said: "Mother Nature is a much better chemist than we are and Mother Nature is able to make these compounds.
"If you have a complicated compound, it's nicer to grow it in a crop, harvest the crop, grind the crop out and extract it than try to make it."
But more research is needed before it can translate into potential therapeutic options, they said.
Dr Weaver added: "What this study does is take the epidemiological evidence and try to refine it and to demonstrate that there are indeed components within coffee that are beneficial to warding off cognitive decline.
"It's interesting but are we suggesting that coffee is a cure? Absolutely not."