Weight loss following infection with intestinal worms is the body's way of fighting off the parasites, University of Manchester researchers have said.
The immune system hijacks a hormone that controls when to stop eating, their study of mice suggests.
This then triggers the type of immune response needed to expel the worms from the gut, PLoS Pathogens reports.
The finding could lead to new ways to treat people with intestinal worms, researchers say.
Researchers first saw a potential link when they were measuring levels of a hormone called cholecystokinin in volunteers after they had been fed a meal.
One man had incredibly high levels and on further investigation it was found he had an intestinal worm infection he had picked up on holiday.
Joining forces with a team specialising in gut worm infections the researchers did a study in mice infected with a worm called Trichinella spiralis.
They found that immune cells called T-cells responded to the worm infection by driving up levels of cholecystokinin.
This increase has a knock-on effect of driving down another hunger hormone, leptin, which influences what type of immune response the body needs to produce.
When they artificially added leptin back into the infected mice, the immune system mounted the wrong response and the intestinal worms remained in the gut for longer.
Nearly one in every four of the world's population are infected with gastrointestinal parasites.
It has long been known that these infections often result in a period of reduced appetite and weight loss but why or how this happens was not understood.
Study author Dr John Worthington said the researchers had looked at only one type of parasitic worm but were now doing tests to see if the same response was produced in response to other worms.
"Naturally you would think that if you are losing weight you are going to have less energy to fight off infection," he said.
"This does the opposite of what you would expect."
Dr Worthington added that eventually they would be looking at whether different treatment or nutrition strategies could be designed to boost this immune effect in people affected with intestinal worms.
Dr Mark Robinson, lecturer in parasite proteomics at Queen's University Belfast, said that diseases of humans and animals caused by parasitic worms were among the most widespread and economically devastating throughout the world and drug resistance was becoming a problem.
"The best way to combat worm infections in the future will be the development of vaccines which represent safer, more environmentally-friendly, alternatives to drugs," he said.
"At present, vaccine development is hampered by a lack of basic understanding of how parasitic worms interact with, and influence, our immune system, so research in this area will hopefully contribute to making new anti-parasite vaccines a reality."