An ancient four-legged whale with hooves has been discovered, providing new insights into how the ancestors of the Earth’s largest mammals made the transition from land to sea.

The giant 42.6m-year-old fossil, discovered in marine sediments along the coast of Peru, appears to have been adapted for a semi-aquatic lifestyle. Its hoofed feet and the shape of its legs suggest it would have been capable of bearing the weight of its bulky four metre long body and walking on land. Other anatomical features, including a powerful tail and webbed feet similar to an otter suggest it was also a strong swimmer.

“Whales are this iconic example of evolution,” said Travis Park, an ancient whale expert at the Natural History Museum in London, who was not involved in the latest study. “They went from small hoofed mammals to the blue whale we have today. It’s so interesting to see how they conquered the oceans.”

Older and smaller whale ancestors with four limbs had been discovered previously, but the latest specimen fills in a crucial gap in knowledge about how the creatures evolved and spread throughout the world’s oceans.

“Other examples from this time were more fragmentary, less complete specimens,” Olivier Lambert, a scientist at the Royal Belgian Institute of Natural Sciences and first author of the study published in the journal Current Biology. “We didn’t have a clear indication about their swimming and walking abilities.”

The latest specimen proves that early whales could swim for days or possibly weeks at a time while retaining their ability to rove around on land.

“Even though it could swim in the water [with] no problem, it still had little hooves on its fingers and toes,” said Park. “It’d be a lot more capable than seals at getting around on land.”

Its sharp teeth and long snout suggest the early whales may have eaten fish or crustaceans.

The location of the latest discovery is also critical. Previously, far older whale ancestors dating to about 53m years ago have been discovered in India and Pakistan. Until now scientists have disputed when and how whales first dispersed to the Americas and beyond.

The Peruvian fossil suggests the first whales would have crossed the South Atlantic, helped by westward surface currents and the fact that, at the time, the distance between the two continents was half what it is today.

The last few tail vertebrae are missing and so it is not clear if the creature’s tail would have featured the large paddle, known as a fluke, that allows some modern whales to power themselves along at speeds of more than 30mph (48 km/h). But it must have been an accomplished swimmer to have survived for days or even weeks at sea.

The fossil was excavated in 2011 by an international team, including members from Peru, France, Italy, the Netherlands, and Belgium. It has since been named Peregocetus pacificus, meaning “the travelling whale that reached the Pacific”.

According to Lambert, it is likely that whales would initially have had to return to land for certain activities such as mating and giving birth to young. The first fully aquatic whales date to around 41m to 35m years ago, filling an ecological niche left vacant when the last marine reptiles – along with the dinosaurs – went extinct 66m years ago.