Mice which were given the compound quercetin - which is found in red onions, grapes, blueberries, broccoli and many other varieties of fruits and vegetables - were less likely to contract the flu than those which did not receive the substance.
Previous studies on cells in the laboratory have also shown that quercetin has antiviral properties.
Mark Davis, a researcher at the University of South Carolina, commented: "Quercetin was used because of its documented widespread health benefits, which include antiviral activity, abundance in the diet and reported lack of side effects when used as a dietary supplement or food additive."
The study also found that mice which exercised to the point of fatigue for three days were more likely to develop the flu than mice which did not exercise, but quercetin was able to cancel out the added risk.
If the findings are repeated in humans, they will provide further support for the current advice to eat at least five portions of fruits and vegetables a day.