Vitamin D could help control a gene known to increase the multiple sclerosis risk. Proteins activated by the vitamin bind to a particular DNA sequence next to the gene, altering its function.
Thus Vitamin D supplements taken during pregnancy and early in life could prevent the disease, according to research published in the PLoS Genetics journal.
Scientists at the University of Oxford and University of British Columbia looked at a section of the genome on chromosome six which had been shown to have the strongest effect on MS risk.
Whilst one in 1,000 people in the UK are likely to develop MS, this number rises to around one in 300 amongst those carrying a single copy of the gene variant - known as DRB1*1501 - and one in 100 of those carrying two copies.
Researchers said that vitamin D deficiency in mothers or even in a previous generation might lead to altered expression of the gene in their offspring.
Exactly how the gene-environment interaction alters MS risk is yet to be determined. One explanation could be an effect on the thymus - a part of the immune system which produces T cells to attack invaders such as bacteria and viruses.
It is thought that in people who carry the gene variant, a lack of vitamin D during early life might impair the ability of the thymus to delete rogue T cells, which then go on to attack the body, leading to a loss of myelin on the nerve fibres.
Co-author, Professor George Ebers, from the Wellcome Trust Centre for Human Genetics, at the University of Oxford, said it had been known for a long time that genes and the environment determine MS risk.
"Here we show that the main environmental risk candidate - vitamin D - and the main gene region are directly linked and interact."
Study leader, Dr Sreeram Ramagopalan, added: "Our study implies that taking vitamin D supplements during pregnancy and the early years may reduce the risk of a child developing MS in later life."
The condition, results from the loss of nerve fibres and their protective myelin sheath in the brain and spinal cord, causing neurological damage.
It is not entirely clear what causes MS but other research has suggested vitamin D, produced in the body through exposure to sunlight plays a part.
Specifically there is evidence that populations from Northern Europe have an increased risk of developing MS if they live in areas receiving less sunshine.
Various pieces of research have also pointed to genetic causes.
Simon Gillespie, chief executive of the MS Society, said: "These remarkable results tie together leading theories about the environment, genes and MS but they are only part of the jigsaw.
"This discovery opens up new avenues of MS research and future experiments will help put the pieces together."
The government already advises that pregnant and breastfeeding women make sure they get enough vitamin D, taking supplements if necessary.
And it is also recommended that children under five take daily vitamin D supplements.