Ecology was the study of the distribution of lifeforms throughout the galaxy, and how those lifeforms interacted with other lifeforms and their environments. It was a multi-disciplinary science which focused on a broad range of studies relating to living organisms. Ecology was generally considered to be a branch of biology.
Typically, several ecologies would develop independently on a class M world. These were usually separated by large distances, although there were some rare occurrences where vastly different ecologies co-existed significantly close to one another. Some examples of this included the planet Lactra VII and the Genesis Planet. (TAS: "The Eye of the Beholder"; Star Trek III: The Search for Spock)
In 2269, when Leonard McCoy expressed surprise at Cyrano Jones's assertion that his "safe" tribbles didn't reproduce, Jones explained that they'd been "genetically engineered for compatibility with humanoid ecologies". Koloth described Jones' actions as ecological sabotage. (TAS: "More Tribbles, More Troubles") Worf would later echo his sentiments, calling tribbles "an ecological menace, a plague to be wiped out". (DS9: "Trials and Tribble-ations")
According to Kathryn Janeway, the fictional R'Kaal were ecological extremists, to the point of banning warp travel through their territory, as they believed conventional warp engines could damage subspace. (VOY: "Renaissance Man")