Sloths aren’t the most impressive swimmers. When today’s two- and three-toed sloths take a dip, they bob along in an awkward doggy paddle. But there used to be sloths that evolution had specifically adapted to be at home in the water. Over the course of four million years, one lineage of giant sloth shuffled into the seas.

The classic image of a giant sloth is of a bulky mammal lazily plucking leaves in an Ice Age forest. But the swimming sloths—named Thalassocnus—lived along the beaches of Peru between 8 and 4 million years ago. There were no tree stands here for the sloths to waddle among. The sea met the desert, and it was in the waves that the sloths found their food.

Since these sloths were first described from Peru’s Pisco Formation in 1995, paleontologists have identified five Thalassocnus species that lived along the same seaside one right after the other. And, paired with the fact that they were found with marine animals, the skeletons of these sloths suggested that the herbivores were at home foraging in the shallows. From the first species to the last, Thalassocnus looked like a seaside sloth.

But how did Thalassocnus go where no sloth had gone before? In a paper published in the Proceedings of the Royal Society B, paleontologist Eli Amson and colleagues at the Muséum national d'Histoire naturelle, Paris reveal that the secret of Thalassocnus lies inside the beast’s bones.

Compared to other mammals, sloths have unusually dense bones. This was true of the extinct giant sloths, too, and the successive species of Thalassocnus took this feature much further. After cutting into the ribs and limb bones of the first four Thalassocnus species, Amson and coauthors found that the bones of these sloths became increasingly dense until, in cross section, they had almost entirely lost their hollow central cavity. This condition is called osteosclerosis. And more than that, the sloth species show a swelling of some bones called pachyostosis that allowed the mammals to pack more bone tissue on.

Paleontologists have seen these features in other amphibious mammals. The bones of the earliest whales and sea cows—mammals that were caught transitioning into a fully aquatic life—show the same characteristics. And these changes to bones were not pathological. They track the evolution of skeletons as bone ballast.

While lungs filled with air are vital to keep swimming mammals from drowning, they can also be a liability for diving. Big, air-filled lungs buoy submerged animals up. Denser, swollen bones allowed early whales, sea cows, and, yes, giant sloths to more easily achieve neutral buoyancy underwater and therefore use less energy to stay beneath the surface.

Thalassocnus was far from being the Michael Phelps of the sloth world, though. The sloth still retained the familiar, bulky body shape of its ancestors. Instead of becoming a streamlined swimmer, Thalassocnus probably favored a method used by marine iguanas today. Anchored down by hefty bones, the sloth gripped the bottom with huge claws and scooped up soft plants as it wafted in the surf. Sloths slurped seaweed by the sea shore.