Scientists think caffeine, which is known to help protect the nervous system and has been shown to suppress inflammatory responses in the body, could be the key to why coffee has an effect.
The authors, writing in the Journal of Neurology, Neurosurgery and Psychiatry, stressed theirs was an observational study, so no firm conclusions could be drawn about cause and effect.
But they concluded: "Lower odds of MS with increasing consumption of coffee were observed, regardless of whether coffee consumption at disease onset or five or 10 years prior to disease onset was considered.
"In accordance with studies in animal models of MS, high consumption of coffee may decrease the risk of developing MS."
Dr Emma Gray, head of clinical trials at the MS Society, said: "This study provides new evidence that the link between the risk of developing MS and coffee consumption is worth exploring.
"There are more than 100,000 people with MS in the UK and we don't yet fully understand what causes it.
"While more studies are needed in this area, we welcome any research that offers new insights into risk factors for MS."