In the rats given a high-fat diet and an exercise wheel, the early extra physical activity caused inflammation-linked genes to be turned down.
High-fat diets early in life are known to turn up, or increase the activity of other genes that cause inflammation.
Inflammation is the body's natural self-protective response to acute infection or injury, but the ongoing, low-grade inflammation linked to high-fat diets can harm cells and tissues and raise the risk of obesity, heart disease, cancer and other diseases.
Exercise also altered the way the rats' bones metabolised energy from food, changing energy pathways that disrupt the body's response to a high-calorie diet.
"What was remarkable was that these changes lasted long after the rats stopped doing that extra exercise - into their mid-life," Liggins molecular geneticist Dr Justin O'Sullivan said.
"The bone marrow carried a memory of the effects of exercise."
This was the first demonstration of a long-lasting effect of exercise past puberty.
"The rats still got fat, but that early extra exercise basically set them up so that even though they put on weight they didn't have the same profile of negative effects that is common with a high-fat diet."
This may help scientists understand why, even though obesity and diabetes are often linked, some people with obesity do not develop diabetes, he said.
"It also strongly emphasises the health benefits of exercise for children."
Study co-author Professor Mark Vickers said rising rates of overweight and obesity in children meant it was important to understand the effects of these conditions on bone health.
A third of Kiwi children, and one in four Australian children, were now considered either obese or overweight.
The most recent Ministry of Health figures showed one in nine Kiwi children aged 2-14 years were obese - a rate of 11 per cent - and a further 21 per cent of children were overweight but not obese.
"Obesity is governed by many genes," Vickers said.
"This work highlights the utility of small animal models in teasing out gene-environment interactions in health and disease."
Another co-author, bone specialist Professor Elwyn Firth, said childhood and adolescence were periods of "rapid" bone growth.
"If you reach optimal bone mass early in life, you're less likely to suffer from broken bones or other bone-related problems as an adult," he said.
"Load-bearing from exercise and higher bodyweight is good for growing bones, but this and other evidence shows that if the extra weight comes from higher body fat mass, bone development may be subnormal.
"Bone metabolism strongly influences energy metabolism in the body, and metabolism - what you do with energy from diet - is the central crux of why some children and adults become obese."
The team hoped to repeat the experiment to see if the changes persist into old age, and if varying the exercise - when it begins, how much the rats do, and how long they do it for - could alter other genes, affecting other aspects of fat metabolism beneficially.