It says five or more daily portions should be enough to counteract culprit versions of a gene on chromosome 9, thought to be possessed by a fifth of people of European ancestry.
Healthy diets appeared to weaken its effect.
The US researchers investigated more than 27,000 people for their work.
The findings were published in Plos Medicine journal.
These participants came from around the globe, including Europe, China and Latin America.
The results suggest that individuals with high risk 9p21 gene versions who consumed a diet packed with raw vegetables, fruits and berries had a similar risk of heart attack as those with a low-risk variant of the same gene.
Researcher Prof Sonia Anand, of McMaster University, said: 'Our results support the public health recommendation to consume more than five servings of fruits or vegetables as a way to promote good health.'
The scientists, who also included staff from McGill University, say they now need to do more work to establish how diet might have this effect on genes.
Judy O'Sullivan of the British Heart Foundation said the findings should serve as a reminder that while lifestyle and genes could increase heart risk, the way the two interacted with each other was also very important.
'The relationship between the two is often very complicated and we don't yet have all the answers, but the message appears to be very simple - eating lots of fruit and vegetables is great news for our heart health.' - BBC