History
Earth's most ancient known fossils are layered rocks called stromatolites, formed by bacteria (primarily cyanobacteria) in warm shallow bays. The oldest stromatolites are an estimated 3.5 billion years old. Cyanobacteria are thought to have been the first oxygen-producing organisms on Earth.
Function
Just like plants on land, cyanobacteria use chlorophyll and carotenoids to capture light energy for photosynthesis, producing oxygen and consuming carbon dioxide in the process. Some cyanobacteria are nitrogen-fixers, meaning they can convert largely inert atmospheric nitrogen into a form that living organisms can use. This activity is very important for marine and freshwater environments, since nitrogen is essential for all known forms of life.
The Endosymbiotic Hypothesis
Chloroplasts are structures inside the cells of algae and plants that carry out photosynthesis. It's currently believed that early eukaryotic cells (cells with a nucleus) acquired chloroplasts by engulfing cyanobacteria, which became able to live inside the host cell so that both derived an advantage from the relationship. This theory is called the endosymbiotic hypothesis.