Pterosaurs, dragon-like flying reptiles that soared over the heads of the dinosaurs, were just taking off when a giant meteor impact wiped them out along with their Earth-bound cousins, new fossil discoveries suggest.
Previously it was thought that by the time the dinosaurs vanished pterosaurs were already well in decline.
But six new fossils unearthed from phosphate mines in northern Morocco paint a very different picture of what happened to the beasts, some of which were as large as a light aircraft.
Far from spiralling slowly into extinction, the creatures were flourishing 66 million years ago when an asteroid or comet six to nine miles wide smashed in to the Earth off the coast of Mexico, scientists now believe.
Both the pterosaurs and nearly all the dinosaurs were killed off in the mass extinction that followed the cataclysm. The only dinosaurs to survive were those that morphed into modern birds.
The new species ranged in wingspan from a little over two metres (six feet) to almost 10 metres (30 feet) and weighed up to 200 kg (440 pounds).
As well as differing in size, they also varied greatly in body shape, suggesting they occupied distinct ecological niches.
Dr Brian Andres from the University of Texas, a member of the team studying the finds, said: "The Moroccan fossils tell the last chapter of the pterosaurs' story - and they tell us pterosaurs dominated the skies over the land and sea, as they had for the previous 150 million years."
A description of the fossils appears in the journal Public Library of Science Biology.
British co-author Dr Nick Longrich, from the University of Bath, explained why pterosaur fossils were so rare, giving a false impression of their population size and diversity.
He said: "To grow so large and still be able to fly, pterosaurs evolved incredibly lightweight skeletons, with the bones reduced to thin-walled, hollow tubes like the frame of a carbon-fibre racing bike.
"But unfortunately, that means these bones are fragile, and so almost none survive as fossils."
Some 200 pterosaur specimens were recovered from the Moroccan mines, ranging from bone fragments to partially intact skeletons.
Scientists now know that the region supported at least seven species of the creatures from three different families. More could still be discovered, the team believes.
Moroccan palaeontologist and co-author Professor Nour-Eddine Jalil, from the Museum of Natural History in Paris, said: "This is a fabulous discovery of pterosaurs from Morocco - they tell us their amazing diversity while we thought them in decline.
"The Moroccan phosphates are an open window on a key moment in the history of the Earth, one that shortly preceded the global crisis that swept away, among others, dinosaurs and marine reptiles."