(Health.com) -- All those late nights spent trolling Facebook, texting friends, and cramming for tests may be taking a toll on teenagers' diets, a new study suggests.

Teens who average fewer than eight hours of sleep on weeknights tend to eat more fatty foods and high-calorie snacks than their better-rested peers, according to the study, which was published in the journal Sleep.

These unhealthy eating patterns can build up over time, and can lead to entrenched bad habits and weight gain, says Susan Redline, M.D., the senior author of the study and a professor of sleep medicine at Harvard Medical School, in Boston.

Research "clearly has shown [that] individuals getting insufficient amounts of sleep are more likely to be obese and gain weight over time," Redline says. "Among adolescents, the sleep-deprived are much more likely to consume more calories and to eat diets much richer in fats and high-density foods."

The study didn't show that sleep patterns caused teens to become overweight, but Redline and her colleagues did find that the 18 percent of teens in the study who were obese were less likely to get eight hours of sleep than the teens of average weight.

It's not clear why sleeping less may send teens to the fridge more often. One explanation involves the hormones leptin and ghrelin, which regulate appetite.

Not getting enough sleep has been shown to reduce the production of these hormones, which can make a person feel hungrier and fuel cravings for high-calorie snacks.

Social and cultural factors could also play a role, says Kristen Knutson, Ph.D., an assistant professor of pulmonary and critical care medicine at the University of Chicago.

Although Redline and her colleagues took age, race, and parental education into account in their analysis, parenting style and other hard-to-identify factors could have influenced the data.

"If there's no chips in the house, [teenagers] are not going to choose that to eat," says Knutson, who was not involved in the current study but has researched the health effects of short sleep.

It may also be that spending more time awake simply provides more opportunities to snack, Redline says.

The study included 240 teenagers between the ages of 16 and 19 who were part of a larger study on sleep habits and health. The researchers measured the teens' sleep duration using wrist monitors, and on two separate occasions asked them to list the foods they'd eaten in the previous 24 hours.

The teens averaged about 7.5 hours of sleep each weeknight -- well shy of the nine hours the American Academy of Sleep Medicine recommends for this age group. Only about one-third of the teens slept for eight hours or more.

Compared with their better-rested peers, sleep-deprived teens got about 2 percent more of their daily calories from fat and 3 percent fewer calories from carbohydrates, the study found. And the teens who slept less than eight hours were more likely to get their calories from snacks -- especially the girls.

"This study goes out into the real world and finds that short sleep is...associated with dietary choices and increased appetite," Knutson says.

Even though snacking can be a part of a healthy diet, eating at times of day that are misaligned with the body's clock can alter metabolism and make a person more likely to gain weight, according to Redline. More of the sleep-deprived teens consumed a significant amount of calories between the hours of 5 a.m. and 7 a.m., she notes.

"Teens tend to be what we call 'phase-delayed,' so their body's natural tendency is to push them towards later bedtimes," says Redline. "Then if school is pushing them to wake up early, they're going to be sleep-deprived, and perhaps eating in the very early hours when their metabolic system isn't really geared up to deal with that many calories."

The study findings should serve as a reminder to teens and parents alike that sleep -- not just diet and exercise -- is a key part of a healthy lifestyle, Knutson says.

"We need to let parents know that bedtime is important for the health of their kids," she says.