If two species have too close a niche, they evolve different characteristics so as to reduce competition between them. Diversity and complexity are the outcome. But they do not lead to chaos. Instead evolution weaves the wealth of species into a web of interdependence. Herbivores eat plants.
Predators eat herbivores and each other.
Plants and animals die. Decomposers recycle their bodies into soil. Soil feeds plants. And so on in self-sustaining cycles. Species in the same habitat evolve together to create ecosystems in which all parts work together through complex cycles and balances.