Martin Poole

We know that eating lots of fruits and vegetables is good for the heart, but can a healthy diet really overcome the effect of genes that boost your risk for heart problems?

Yes, it can, according to researchers in Canada who studied data on more than 27,000 people to figure out which contributes more to the risk of heart disease: environment or genes. The researchers focused on a group of people with specific genetic variants that are known to increase the risk of heart disease. They found that people who had the variants but ate lots raw fruits and vegetable showed no increased heart risk, compared with those who had a less healthy diet, who were twice as likely to have a heart attack.

“We found that among those with the high-risk genotype, if they consumed a diet high in vegetables and fruits, their risk for heart attack did not increase despite their having the high-risk gene profile,” says Dr. Sonia Anand, a professor of medicine at epidemiology at McMaster University and one of the co-authors of the study published in PLoS Medicine.

The scientists relied on two large sets of data, one that involved more than 8,100 people in 52 different countries, comparing those who had had heart attacks with similar people who had not, and another set from Finland including more than 19,000 participants who were surveyed every five years for heart-related deaths, heart attacks, angina, stroke or bypass and angioplasty procedures. Both groups also answered detailed questionnaires about what they ate.

The research team divided the enrollees in the first study into three diet groups based on their answers on 19 food-related questions. People were classified as eating primarily “western,” “oriental,” or “prudent” diets. Western diets included eggs, meats, fried and salty food, sugar and desserts; the oriental diet included more tofu, pickled foods, green leafy vegetables, soy sauce and less sugar. Finally, the prudent diet eaters followed what most of us would recognize as a heart-healthy menu: raw vegetables, fruits, nuts and some dairy products. Participants in the larger Finnish study were also placed in the prudent group, based on their intake of fruits, vegetables and berries.

MORE: To Help Erectile Dysfunction, Treat the Heart

The scientists further separated the participants within the various dietary groups by their genetic profiles. Specifically, the authors looked for four variants on a region of DNA on chromosome 9 that is known to boost heart attack risk by up to 20% in carriers, compared with those without the variants. People in the current study who had the high-risk genes — in this case, two versions of them, one from their mother and one from their father — were two times more likely to have a heart attack if their diet was lacking in fruits and veggies, compared with the “prudent” eaters.

That suggests that diet can make a real difference in heart disease risk, even when that risk is genetically based. “It means that perhaps our family history, or genetic risk, is modifiable,” says Anand. “Despite not being able to change our genetics, if we are able to modify the effect or expression of our genes. That’s exciting.”

The scientists were encouraged to study this effect after animal studies showed that heart muscle in mice bred without the high-risk genes had different responses to different diets. That served as hint that perhaps what we eat could alter the way the heart functions. How that happens isn’t clear yet, but it’s possible that eating lots of fruits and vegetables somehow change the way the genes in this region make their proteins or enzymes, prompting them to produce factors that may counteract the effects of heart risk factors like atherosclerosis.

MORE: Environmental Toxins Linked to Atherosclerosis, Heart Risk

However it works, the fact that something within our control can combat the effects of disease-causing genes should be good news, especially for those of us who try valiantly to resist meats and processed foods and to stick with a more raw foods-focused diet. So, when it comes to heart health, it looks like Mother knew best: Eat your vegetables.

Alice Park is a writer at TIME. Find her on Twitter at @aliceparkny. You can also continue the discussion on TIME’s Facebook page and on Twitter at @TIME.