Crocodiles may have outlived the dinosaurs, but it was only recently that researchers figured out how.

A new study shows for the first time how ancient crocodiles evolved and survived when they lived among dinosaurs. Unlike modern crocodiles that live in freshwater habitats, ancient crocodiles were diverse – some could run like dogs on land and others lived in open ocean.

"The ancestors of today's crocodiles have a fascinating history that is relatively unknown compared to their dinosaur counterparts. They were very different creatures to the ones we are familiar with today, much more diverse and, as this research shows, their ability to adapt was quite remarkable,” Tom Stubbs, who led the research at the University of Bristol, said in a statement.   

The study published in the journal Proceedings of the Royal Society B showed how the jaws of ancient crocodiles evolved in such a way to help the reptiles adapt to different environments 235 to 65 million years ago.

Researchers came to the conclusion after examining the shape and functions of ancient crocodiles’ lower jaws. For the first time they were able to show that after the dinosaurs went extinct, ancient crocodiles’ jaws adapted to their changing surroundings in order to feed in different ecologies and terrestrial environments.

"Our results show that the ability to exploit a variety of different food resources and habitats, by evolving many different jaw shapes, was crucial to recovering from the end-Triassic extinction and most likely contributed to the success of Mesozoic crocodiles living in the shadow of the dinosaurs," Dr. Stephanie Pierce of the Royal Veterinary College, said in a statement.

The later Cretaceous period also saw significant adaption in ancient crocodiles, according to the study’s findings. Instead of their jaws, Cretaceous crocodiles adopted an armadillo-like body armor to survive in their surroundings.

"Their evolution and anatomical variation during the Mesozoic Era was exceptional,” Stubbs said. “They evolved lifestyles and feeding ecologies unlike anything seen today."