This image shows the tapeworm that the patient discharged from his body. It measured 20 feet 4 inches long.

A man in China who enjoyed eating raw beef became infected with a parasite — a 20-foot-long tapeworm —that came from including this food in his diet, a new case report reveals.

The parasite had attached to the 38-year-old man's small intestine and had likely been inside him for at least two years before doctors diagnosed the infection as beef tapeworm of the species Taenia saginata, according to the case report, published online today (Jan. 20) in The New England Journal of Medicine.

Tapeworm infections are quite rare in Central China, where this case took place, said Jian Li, of the department of infectious diseases at Renmin Hospital in Shiyan, China, who diagnosed the man and co-authored the case report.

Although the tapeworm infection rate is quite high in the northwest and southwest districts of China, this was the first case of tapeworm seen in this part of China in 30 years, Li said.

Tapeworms are common globally, and Ethiopia, a country where people like to eat raw meat, has one of the highest rates of infection from beef tapeworm, said Dr. Peter Hotez, dean of the National School of Tropical Medicine at Baylor College of Medicine in Houston, Texas, who was not involved in the case.

But beef tapeworms are rare in the United States, Hotez said.

According to the case report, the man went to see his doctor in the spring of 2015 because he was having stomach pain, vomiting, had lost his appetite, felt weak and was losing weight, Li told Live Science. The symptoms had begun just three days earlier, but the man had already lost about 5 to 10 kilograms (11 to 22 lbs.), he said. [The 10 Most Diabolical and Disgusting Parasites]

When the man came to the doctor's office, he brought a fragment of the parasite with him that he found in his stool, Li said. He also told his doctor that he liked to eat raw beef.

From these two pieces of information — the parasite fragment in his stool, which was later examined under a microscope, and his consumption of raw beef — the doctors deduced that the man was infected with a beef tapeworm, Li said.

Over the past two years, the man's medical history also showed that he had been seen by several different doctors and given treatment for stomachaches, pain in his abdomen and anemia, which is a low level of healthy red blood cells.

This image shows one of the tapeworm's proglottids. A proglottid is a segment of a tapeworm that may contain eggs, and be shed in a person's feces as part of the worm's reproductive cycle. Eggs are visible inside this proglottid. (Image credit: The New England Journal of Medicine ©2016)

Tapeworms can live for years in a person's intestines and cause no symptoms, or only mild ones, such as fullness or nausea after eating, Hotez told Live Science.

But it takes a long time for tapeworms to grow as long as this one did, Hotez explained, adding that other types of invertebrates, an animal group that includes worms, flies, snails and mosquitoes, tend to not live as long as tapeworms do.

No more rare beef

Cattle can become infected with T. saginata when they are out to pasture and feed on the eggs of the parasite, which were passed in human feces, especially in areas of poor sanitation, according to the Centers for Disease Control and Prevention (CDC). Those tapeworm eggs can hatch inside the cow, penetrate the intestinal wall and then circulate to the animal's muscles.

People can become infected with the parasite by eating raw or undercooked beef from a contaminated cow. The tapeworm eggs and larvae can migrate to the small intestine, attach to the intestinal wall and mature into an adult tapeworm, the CDC says.

An adult tapeworm can produce eggs and tapeworm segments that are shed from the body in feces, according to the CDC.

Tapeworms from a related species, known as Taenia solium, can be acquired from eating raw or undercooked pork. But beef tapeworms tend to grow larger in size (up to 33 feet) and produce more eggs than pork tapeworms, according to the CDC.

If the larvae of a pork tapeworm have migrated out of the intestines and formed cysts in other tissues, such as the brain, they may cause neurological symptoms, including seizures. Pork tapeworms are a major cause of hundreds of thousands of cases of epilepsy worldwide, Hotez said. [Top 7 Germs in Food That Make You Sick]

This egg from the tapeworm (seen here under a microscope) was found in the man's stool. (Image credit: The New England Journal of Medicine ©2016)

Both beef and pork tapeworm are considered "neglected tropical diseases," a category of infectious diseases that have never gotten much attention until recently, Hotez said.

In the case report, the man's doctors explain that they treated their patient with an oral prescription medication that caused him to pass the long tapeworm out of his body 2.5 hours later.

Three months after expelling the tapeworm, the man felt better. His appetite and weight returned to normal.

But he likely will never eat raw or rare beef again, Li suspects. Being infected with a parasite for at least two years was a very unforgettable experience for the man, he explained.

"It was physically, emotionally and financially exhausting for him," Li said.

Follow Live Science @livescience, Facebook & Google+. Originally published on Live Science.