Because they also wanted to include a large and varying group of people in the study, they turned to the trove of data gathered in Britain in the U.K. Biobank, which houses health information about more than 500,000 men and women who were between ages 40 and 69 at the study’s start in 2006.

All of the participants had provided blood and saliva samples for genetic testing, filled out extensive questionnaires about their exercise and other health habits, and in some cases, sweated on a stationary bike or treadmill and later squeezed a vise-like gadget to quantify their aerobic fitness and muscular strength. Some also wore activity monitors for a week to objectively track how much they moved.

The researchers zeroed in on the 482,702 men and women in the study who had had no known heart disease at the start, genetically typing their tissue samples, looking for various snippets of genes known to raise heart disease risk. They also stratified them into three groups, based on how fit and strong they were.

Then they checked to see whether any of the men and women developed heart disease within the next six years or so. Many did, according to their health records, especially if they carried any of the gene variants associated with cardiac conditions.

But physical fitness changed that calculus significantly, the data showed.

Those men and women with the highest aerobic fitness halved their statistical likelihood of developing heart disease, no matter how worrisome their genetic profiles, the scientists found.

In essence, if people were fit, they were less likely to have heart problems than someone who was less fit, even if their genes predicted heart disease.

Stout grip strength likewise reduced cardiac-disease risk, although not quite to the same extent.

“What this tells us is that you can mitigate some of your genetic risk for heart disease by being fit, no matter how high that risk may be,” says Dr. Erik Ingelsson, a professor of medicine at Stanford who oversaw the study.