The dinosaurs weren't destined to go extinct - they were just unlucky.
The extinction of the dinosaurs was not was caused by a perfect storm of "colossal bad luck", according to new research.
The prehistoric creatures might have survived the asteroid strike which led to their extinction if it had come slightly earlier or later in history, scientists found.
But when the 10km-wide asteroid hit what is now Mexico some 66 million years ago they were experiencing environmental upheaval which left them vulnerable.
The new study by an international team of palaeontologists led by the University of Edinburgh looked at an updated catalogue of dinosaur fossils, mostly from North America.
They found that widespread volcanic activity, changing sea levels and varying temperatures had weakened the dinosaurs' food chain when disaster struck.
If the asteroid impact had come a few million years earlier, when the range of species was bigger and food chains more robust, they may have survived.
Likewise, if it had come later in history when new species had been given the chance to evolve, they might have escaped extinction.
But when the asteroid struck - causing tsunamis, earthquakes, wildfires, sudden temperature swings and other environmental changes - the already weakened dinosaur kingdom was wiped out one species after another.
The only dinosaurs to survive were those who could fly, which evolved to become the birds of today.
Dr Steve Brusatte, of the University of Edinburgh's School of GeoSciences, said: "The dinosaurs were victims of colossal bad luck.
"Not only did a giant asteroid strike, but it happened at the worst possible time, when their ecosystems were vulnerable.
"Our new findings help clarify one of the enduring mysteries of science."
Dr Richard Butler, from the University of Birmingham, said there was nothing to suggest that dinosaurs were doomed to extinction when the asteroid hit.
"Without that asteroid, the dinosaurs would probably still be here, and we very probably would not," he added.