In ecology, an ecosystem is a naturally occurring assemblage of organisms (plant, animal and other living organisms—also referred to as a biotic community or biocoenosis) living together with their environment (or biotope), functioning as a loose unit.

An ecosystem is a dynamic and complex whole, interacting as an ecological unit. Some consider this the basic unit in ecology: a structured functional unit in equilibrium, characterized by energy and matter flows between its constituent elements. Others consider this vision limited.

The term ecosystem first appeared in a 1935 publication by the British ecologist Arthur Tansley (Tansley, 1935). However, the term had been coined already in 1930 by Tansley's colleague Roy Clapham, who was asked if he could think of a suitable word to denote the physical and biological components of an environment considered in relation to each other as a unit. Tansley expanded on the term in his later work, adding the ecotope concept to define the spatial context of ecosystems (Tansley, 1939). Modern usage of the term derives from the work of Raymond Lindeman in his classic study of a Minnesota lake (Lindeman, 1942).

The organisms in an ecosystem are usually well balanced with each other and their environment. This balance is achieved through various types of symbiosis, such as predation, parasitism, mutualism, commensalism, competition, and amensalism. Introduction of new elements, whether abiotic or biotic, into an ecosystem tend to have a disruptive effect. In some cases, this can lead to ecological collapse and the death of many native species. The abstract notion of ecological health attempts to measure the robustness and recovery capacity for an ecosystem

The size of an ecosystem can vary widely. It may be a whole forest, as well as a small pond. Different ecosystems are often separated by geographical barriers, like deserts, mountains or oceans, or are isolated otherwise, like lakes or rivers. As these borders are never rigid, ecosystems tend to blend into each other. As a result, the whole earth can be seen as a single ecosystem, or a lake can be divided into several ecosystems, depending on the scale used.