The fragmentation of tropical rainforests 300 million years ago helped pave the way for the rise of the dinosaurs, a new study suggests.
In the Carboniferous period, North America and Europe lay at the equator and were covered by steamy rainforest.
Global warming is thought to have brought about the collapse of these tropical habitats, triggering an evolutionary burst among reptiles.
The work, by a British team, is published in the journal Geology.
The forests that covered the ancient supercontinent of Euramerica are colloquially referred to as the Coal Forests.
They are so called because they accumulated a large amount of peat, which later turned into the coal that is mined today.
Towards the end of the Carboniferous, the Earth's climate is thought to have grown hotter and drier.
"Climate change caused rainforests to fragment into small 'islands' of forest," said co-author Howard Falcon-Lang, from Royal Holloway, University of London.
Dr Falcon-Lang continued: "This isolated populations of reptiles, and each community evolved in separate directions, leading to an increase in diversity."
To reach their conclusions, the scientists studied the fossil record of reptiles before and after the collapse of the rainforests.
They showed that reptiles became more diverse and even changed their diets as they struggled to adapt to a rapidly changing climate and environment.
Professor Mike Benton, from the University of Bristol, said: "This is a classic ecological response to habitat fragmentation.
"You see the same process happening today whenever a group of animals becomes isolated from its parent population.
"It's been studied on traffic islands between major road systems or, as Charles Darwin famously observed in the Galapagos, on oceanic islands."
His Bristol colleague Sarda Sahney commented: "It is fascinating that even in the face of devastating ecosystem-collapse, animals may continue to diversify."
Amphibians appear to have been hardest hit by the collapse of the rainforests. The relative success of reptiles may have been due to physical adaptations in which they differed from amphibians.
Firstly, the hard-shelled eggs of reptiles could be laid on dry land (most amphibians lay theirs in water). Secondly, reptiles possess protective scales that help them retain moisture (amphibian skin is very permeable to water).
"These key adaptations freed them from the aquatic habitats to which amphibians were tied and gave them ecologic advantage in the widespread drylands that developed," the researchers write in Geology.