The fossils of two extinct shrew-sized animals that existed about 160 million years ago – one that lived in trees and one that burrowed underground – reveal wide-ranging ecological diversity among the earliest mammals, similar to that found in modern mammals.

The new fossils have been described as two previously unknown mammaliaforms (extinct relatives of modern mammals) by scientists in the US and in China. They include a tree-dwelling creature, Agilodocodon scansorius, and a mole-like subterranean animal Docofosser brachydactylus.

Before the 2000s, it was generally thought Mesozoic mammals couldn't diversify much in the dinosaur-dominated ecosystem

They represent new docodonts – an order of extinct early ancestral mammals without any living descendants – which co-existed with dinosaurs in the Mesozoic era.

The discovery is the latest evidence to suggest parallels between modern mammals and mammaliaforms in terms of their adaptations to diverse ecological habitats and their genes.

Surprising specialisation

Modern mammals are extraordinarily diverse. But whether such a range of adaptations was found as early as the mammaliaforms has been debated.

“Before the 2000s, it was generally thought Mesozoic mammals could not diversify much in the dinosaur-dominated ecosystem,” said Dr Zhe-Xi Luo from the University of Chicago’s Department of Organismal Biology and Anatomy, who co-authored the papers analysing Agilodocodon scansorius and Docofosser brachydactylus.

But fossil discoveries in recent years have built a different picture, he said. “In the last 10-15 years, palaeontologists found many Mesozoic mammals with very interesting functional and ecological specialisations.”

The new research suggests docodonts adapted to a very broad range of environments such as arboreal and subterranean ones, despite competition from dinosaurs.

Researchers from the University of Chicago in the US and the Beijing Museum of Natural History in China described the extinct beasts in two separate studies published in the journal Science.

A team had been studying the fossils kept at the Beijing Museum of Natural History since 2013.

The remarkably preserved 165 million-year-old Agilodocodon scansorius from the Middle Jurassic period showed many skeletal adaptations for living in trees. Its horny claws would have been perfect for climbing and its incisors were adapted to gnaw on bark and feed on tree sap, providing the earliest evidence of “gumnivorous” feeding in mammaliaforms which, in modern mammals, is seen in some New World monkeys.

Its limb proportions, flexible wrist, elbow and ankle joints for greater mobility are all typical of climbing animals. The researchers estimated Agilodocodon scansorius would have measured about 14cm (5.5 inches) from head to tail.

Docofosser brachydactylus, preserved in a 160 million-year-old fossil from the late Jurassic period, had a skeletal structure and proportions much like modern-day golden moles (Chrysochloridae). The creature had shovel-like fingers and short, wide molars – suggesting it was adapted to a subterranean lifestyle.

Some skeletal features of Docofosser and Agilodocodon resemble patterns shaped by genes identified in living animals, according to the research. For example Docofosser’s short and wide digits are very similar to the adaptation found in golden moles, which is influenced by genes.

The structure of Docofosser’s and Agilodocodon’s ribs and spines resemble developmental patterns shaped by genes also identified in living animals. This suggests some genetic mechanisms found in living animals operated long before modern mammals appeared.

The new findings come after the discovery in 2006 of a beaver-like, swimming early mammal Castorocauda lutrasimilis that lived 164 million years ago, which was described by Dr Luo and colleagues. The fossil was surprising because it challenged the thinking at the time that mammals might have been primitive creatures that were confined to land.

“We consistently find with every new fossil that the earliest mammals were just as diverse in both feeding and locomotor adaptations as modern mammals,” Dr Luo said of the new findings.

He added: “These fossils help demonstrate that early mammals did indeed have a wide range of ecological diversity. It appears dinosaurs did not dominate the Mesozoic landscape as much as previously thought.”

You can follow BBC Earth on Facebook, Twitter and Instagram.