In laboratory experiments the plant compounds, called stilbenoids, increased activity of a gene involved in immune function.
Stilbenoids are produced by plants to fight infections. In humans, they appear to affect signalling pathways used by vitamin D.
Laboratory experiments showed that combining the compounds with vitamin D made them much more potent.
The stilbenoid in red grapes is resveratrol, which has already been hailed for its potential inflammation and cancer-fighting properties.
Its counterpart in blueberries is a compound called pterostilbene.
The new findings are published in the journal Molecular Nutrition and Food Research.
Scientists screened 446 compounds for their immune system activity.
"Out of a study of hundreds of compounds, just these two popped right out," said lead researcher Dr Adrian Gombart, from Oregon State University in the US.
"Their synergy with vitamin D.. was significant and intriguing. It's a pretty interesting interaction."
With the help of vitamin D, the compounds significantly boosted activity of the cathelicidin antimicrobial peptide (CAMP) gene.
CAMP has been shown to play a key role in the "innate" immune system, which is the body's first line of defence against infection.
The innate immune response is especially important for fending off bacteria, which are increasingly becoming resistant to antibiotics.
A strong link has been established between adequate vitamin D levels and CAMP gene function.