Blue whales are the largest animals ever to have lived on Earth – but they only evolved their enormous size in the past few million years.

Exactly how baleen whales – filter-feeding whales that include blue, sperm and humpback whales – became so large has been a long-standing evolutionary question. Blue whales can grow up to about 30 metres long and weigh 140,000 kg. To maintain their enormous bulk, they eat about 40 million krill a day.

One traditional theory is that when whale ancestors moved from land to sea about 50 million years ago, they began to grow after being released from the constraints of gravity on land. But that theory has lacked hard evidence to back it up.

Now scientists think they have solved the mystery, and that cooling oceans were the trigger.

Analysis of 63 extinct species of whale has found that the baleens started to become huge about 4.5 million years ago during a period of prolonged ice ages. Several unrelated species began the process of evolving gigantism around that time independently, suggesting that an environmental factor was the cause.

"When we look at whole family tree we see a notable shift in body size in last 4.5 million years. We see the extinction of smaller whales and appearance of larger whales," study author Nicholas Pyenson of the Smithsonian's National Museum of Natural History told IBTimes UK.

"That makes you wonder what's going on? What is driving this?"

The cooling oceans created a disturbance in nutrient flows at the edges of continents that would have made zooplankton – baleen whales' prey – group into more dense packs to make use of the nutrient hotspots, the authors argue.

Blue whale
Blue whales are the largest animals ever to have lived on Earth. Nicholas Pyenson

"Glacial ice sheets yield more run off, more nutrients in coastal environments," Pyenson said. "If you have more coastal run-off of nutrients, you have a larger base of productivity."

Larger whales are much more efficient at eating these large, dense packs of zooplankton than smaller whales, hence the sudden drive to larger body sizes.

But this large body size could now be putting the baleen whales at risk.

"There's a lot of reasons that large baleen whales live on an energetic knife edge. Wouldn't take much change in their food resource to not be able to survive.

"Some have ecological flexibility, with a broad range of prey, such as the gray whale," Pyenson said. "But blue whales are krill specialists. If anything happens to krill, if ocean acidification affects them – then blue whales would suffer."

The research is published in the journal Proceedings of the Royal Society B.