Remains of a reef built 550 million years ago by the first animals to have hard shells have been discovered on dry land in Namibia.
The tiny animals that constructed the reef, known as Cloudina, evolved from soft-bodied ancestors.
Scientists found that the creatures attached themselves to fixed surfaces and each other using a natural cement made from calcium carbonate.
They may have developed their reef-building ability to protect themselves against increased threats from predators.
Reefs also provided access to nutrient-rich currents at a time of growing competition for food and living space.
The development of hard biological structures sparked a dramatic increase in the biodiversity of ocean ecosystems.
Professor Rachel Wood, from the University of Edinburgh, who led the research published in the journal Science, said: "Modern reefs are major centres of biodiversity with sophisticated ecosystems. Animals like corals build reefs to defend against predators and competitors.
"We have found that animals were building reefs even before the evolution of complex animal life, suggesting that there must have been selective pressures in the Pre-Cambrian Period that we have yet to understand."