Early photosynthetic systems, such as those in green and purple sulfur and green and purple nonsulfur bacteria, are thought to have been anoxygenic, and used various other molecules as electron donors rather than water. Green and purple sulfur bacteria are thought to have used hydrogen and sulfur as electron donors. Green nonsulfur bacteria used various amino and other organic acids as an electron donor. Purple nonsulfur bacteria used a variety of nonspecific organic molecules. The use of these molecules is consistent with the geological evidence that Earth's early atmosphere was highly reducing at that time.
Fossils of what are thought to be filamentous photosynthetic organisms have been dated at 3.4 billion years old.
The main source of oxygen in the Earth's atmosphere derives from oxygenic photosynthesis, and its first appearance is sometimes referred to as the oxygen catastrophe. Geological evidence suggests that oxygenic photosynthesis, such as that in cyanobacteria, became important during the Paleoproterozoic era around 2 billion years ago. Modern photosynthesis in plants and most photosynthetic prokaryotes is oxygenic. Oxygenic photosynthesis uses water as an electron donor, which is oxidized to molecular oxygen (O2) in the photosynthetic reaction center.
The Great Oxygenation Event (GOE), also called the Oxygen Catastrophe, Oxygen Crisis, Oxygen Revolution, or Great Oxidation, was the biologically induced appearance of dioxygen (O2) in Earth's atmosphere. Although geological, isotopic, and chemical evidence suggest that this major environmental change happened around 2.3 billion years ago (2.3 Ga), the actual causes and the exact date of the event are very contested amongst the scientific community. It has been argued that current geochemical and biomarker evidence for the development of oxygenic photosynthesis before the Great Oxidation Event has been mostly inconclusive.
Oceanic cyanobacteria, having developed into multicellular forms more than 2.3 billion years ago (approximately 200 million years before the GOE), became the first microbes to produce oxygen by photosynthesis. Before the GOE, any free oxygen they produced was chemically captured by dissolved iron or organic matter. The GOE was the point when these oxygen sinks became saturated and could not capture all of the oxygen that was produced by cyanobacterial photosynthesis. After the GOE, the excess free oxygen started to accumulate in the atmosphere.
The increased production of oxygen set Earth's original atmosphere off balance. Free oxygen is toxic to obligate anaerobic organisms, and the rising concentrations may have wiped out most of the Earth's anaerobic inhabitants at the time. Cyanobacteria were therefore responsible for one of the most significant extinction events in Earth's history. Besides marine cyanobacteria, there is also evidence of cyanobacteria on land.
A spike in chromium contained in ancient rock deposits shows that these rocks, formed underwater, had accumulated chromium washed off from continental shelves by rivers. The researchers chose to focus on chromium because it is not easily dissolved and its release would have required the presence of a powerful acid. One such acid is sulphuric acid, that would have been created through bacterial reactions with pyrite. Though cyanobacteria are responsible for the GOE, they are not the only organisms capable of releasing oxygen. Research has shown that microbial mats of oxygen-producing microbes will produce a thin layer, one or two millimeters thick, of oxygenated water in an otherwise anoxic environment even under thick ice, and before oxygen started accumulating in the atmosphere, organisms living on these mats would already be adapted to being exposed to oxygen. Additionally, the free oxygen reacted with atmospheric methane, a greenhouse gas, greatly reducing its concentration and triggering the Huronian glaciation, possibly the longest snowball Earth episode in Earth's history.
Eventually, aerobic organisms evolved, consuming oxygen and bringing about an equilibrium in its availability. Free oxygen has been an important constituent of the atmosphere ever since.
Explanation from: https://en.wikipedia.org/wiki/Photosynthesis#Evolution and https://en.wikipedia.org/wiki/History_of_Earth#Oxygen_revolution