Although a vegetarian diet has many health benefits, eating meat may not be so terrible for you either, as long as you include plenty of vegetables, too, according to a new study.

In the study, the researchers looked at how different diets affected the types of bacteria in people's guts, and the levels of certain compounds that those gut bacteria produce. They found that not only did the people who ate vegetable-filled diets generally have higher levels of bacteria previously linked to plant-based diets, they also had higher levels of molecules called short-chain fatty acids, which gut bacteria produce and which are beneficial for health.

But diets that also included meat — such as the Mediterranean diet — didn't necessarily spell disaster for gut health. People in the study who closely followed the Mediterranean diet (and ate very little meat) had higher levels of short-chain fatty acids than those who followed it less closely. [5 Ways Gut Bacteria Affect Your Health]

"Western omnivore diets are not necessarily detrimental when a certain consumption level of vegetable foods is included," the authors wrote in the conclusion of their study, published today (Sept. 28) in the journal Gut.

Indeed, the evidence shows that if people do not eat too much meat, and they increase the amounts of fruits, vegetables and legumes in their diet, they are more likely to have a healthy community of gut bacteria, said Danilo Ercolini, an associate professor of microbiology at the University of Naples Federico II in Italy and the lead author of the study.

More On This...

In the study, the researchers recruited healthy vegans, vegetarians and omnivores from different cities in Italy and collected information about their daily diet, along with fecal and urine samples, Ercolini told Live Science. The researchers used the diet information to group people based on how closely they followed the Mediterranean diet.

They also used DNA sequencing to determine the types of bacteria in the gut and chemical analysis to determine the levels of important metabolites, including compounds called short-chain fatty acids and trimethylamine oxide, he said.

Short-chain fatty acids are produced by certain types of gut bacteria when they break down insoluble fiber, Ercolini said. Researchers have found that these molecules play a protective role against different diseases, he said.

In the study, the researchers found that levels of short-chain fatty acids were higher in vegans and vegetarians, as well as all of the study participants who generally followed the Mediterranean diet. In addition, the more fruit, vegetables and legumes people ate — regardless of the type of diet they followed — the higher their levels of short-chain fatty acids.

Trimethylamine oxide, on the other hand, is formed when certain types of gut bacteria break down animal proteins and fat, according to the study. This compound has been linked to increased risk of heart disease, the researchers said.

In the study, the researchers found that people who followed the Mediterranean diet less strictly — for example, by eating more red meat or less vegetables than those who followed it more closely — had higher levels of this compound in their urine.

The machinery in our gut

Taken together, the molecules that are produced by a person's gut bacteria make up what scientists called their "metabolome."

"You can think of the bacteria and other organisms that live in our intestines as machinery in a factory, and you think of the food we eat as the raw materials that are processed in these machines" that ultimately produce an end product, said Dr. James Lewis, a gastroenterologist and professor of medicine at the University of Pennsylvania, who was not involved in the study.

"The metabolome is one example of the end product," Lewis told Live Science.

Gut bacteria has been shown to influence health in many ways. However, it's more likely that the compounds produced by the gut bacteria are what impact our health, rather than the bacteria themselves, he said. These compounds can be beneficial (such as short-chain fatty acids) or harmful (such as trimethylamine oxide), Lewis said.

The "machines" that you turn on more often and the "raw materials" that you bring in may determine whether what's produced is harmful or beneficial, Lewis said.

Although previous research has focused on figuring out which types of bacteria are present in the gut, studying the products of these bacteria is the next logical step in the research, Lewis said.

"To get here, we had to first figure out who's [in the intestines]. Now, we can start thinking about what they're doing," he said.

Ercolini cautioned that the study found only an association, and did not show a cause-and-effect relationship, between diet and higher levels of short-chain fatty acids in the gut. Short-chain fatty acid levels can naturally vary as a result of age and gender, he said.

Further research will be needed to establish how diet can be used to target specific gut bacteria and "make them work properly for us," he said.

Copyright 2015 LiveScience, a Purch company. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.