A chemical in vegetables such as broccoli, cauliflower and cabbage can boost DNA repair in cells and may stop them becoming cancerous, a study says.
Scientists have been looking at why vegetables like broccoli could protect against cancer
Another chemical in soy also performs the same role, the Georgetown University team said.
Although a link has already been found between eating these foods and a reduced cancer risk, this research shows how that might happen.
The research is published in the British Journal of Cancer.
Vegetables such as broccoli were found to contain a compound called I3C.
And a chemical called genistein found in soy beans.
The repair proteins, regulated by genes called BRCA1 and BRCA2, are important for preventing damaged genetic information being passed on to the next generation of cells.
If people have a faulty BRCA gene they are at a higher risk of developing some forms of cancer, including breast, ovarian and prostate cancer.
Low amounts of the BRCA proteins are seen in cancer cells, so the scientists propose higher levels might prevent cancer developing.
Researchers suggest the ability of I3C and genistein to boost the amount of BRCA proteins could explain their protective effects.
Professor Eliot Rosen, who led the research, said: "Studies that monitor people's diets and their health have found links between certain types of food and cancer risk.
"However, before we can say a food protects against cancer, we have to understand how it does this at a molecular level."
He added: "It is now clear that the function of crucial cancer genes can be influenced by compounds in the things we eat.
"Our findings suggest a clear molecular process that would explain the connection between diet and cancer prevention."
Professor John Toy, medical director of Cancer Research UK, which owns the British Journal of Cancer, said: "Diet's role in cancer prevention is complex.
"This research explores an interesting hypothesis as to how certain components of diet can affect cancer risk.
"The evidence is building that these chemical compounds act on some of the genes inside cells that help prevent cancer developing."
But he added: "We still don't know if this is exactly how these chemicals might act in every day life."
However he said it had been established that eating a balanced diet, which was high in fibre plus plenty of fruit and vegetables, lowered the risks of developing many forms of cancer.