Dinosaurs didn't spring suddenly into existence two hundred million years ago, huge, toothy, and hungry for grub. Like all living things, they evolved, slowly and gradually, from previously existing creatures--in this case, a family of primitive reptiles known as the archosaurs ("ruling lizards").
On the face of it, archosaurs weren't all that different from dinosaurs. However, these ancient reptiles were much smaller than most dinosaurs, and they had certain characteristic features (relatively splay-footed postures, for example) that set them apart from their more famous descendants. Paleontologists even believe they may have identified the single genus of archosaur from which all dinosaurs evolved: Lagosuchus ("rabbit crocodile"), a quick, tiny reptile that scurried across the forests of the early Triassic (and that also goes by the name Marasuchus).
Archosaurs - Before or After the Permian Extinction?
This, unfortunately, is where we encounter one of those disagreements so common in paleontology. Scientists are unsure whether archosaurs coexisted with the therapsids (mammal-like reptiles) of the late Permian period (over 250 million years ago), or whether they appeared on the scene after the Permian/Triassic boundary, a geologic upheaveal that killed about three-quarters of all land-dwelling animals on earth. This would place the first archosaurs in the early Triassic period, a few million years later.Also--and somewhat confusingly--it seems that later archosaurs (like Desmatosuchus) coexisted with the earliest dinosaurs (like Eoraptor and Herrerasaurus). In evolutionary terms, this poses no contradiction: evolved animals often wind up living side-by-side with the (relatively unevolved) descendants of their "progenitor" species. But it does pose a problem to paleontologists trying to definitively classify Triassic-period fossils.
Whatever the case, it's undeniable that the Permian Extinction opened up huge swaths of evolutionary territory for the archosaurs, some of which evolved over tens of millions of years into the dinosaurs we know and love today (and others of which went on to spawn pterosaurs and prehistoric crocodiles). As is the case with all species, the slow, winding path taken by dinosaur evolution depended on a variety of factors, including climate, competition, and the availability of food. For example, it's a sure bet that nature would never have allowed Brachiosaurus to evolve if there weren't tons of vegetation around to supply its dietary requirements.
Paths of Dinosaur Evolution
Archosaurs weren't the only lizard-like creatures roaming the earth before the dinosaurs; there were also the therapsids, some of which looked like strange hybrids of mammals and reptiles. To show the strange twists and turns evolution can take, consider one of the most famous therapsids, Cynognathus ("dog jaw"). About the size of a large dog, Cynognathus may have been covered with fur, and it may also have given birth to live young instead of laying eggs. Most astonishingly, it seems likely that Cynognathus had a warm-blooded metabolism--anticipating the physiology of the first mammals that evolved from the therapsids during the late Triassic period.
The point of this story is that evolution isn't necessarily a linear process: the same adaptations can appear in widely separated epochs, depending on environmental conditions. Yes, we know that dinosaurs evolved from archosaurs, but play the tape of history over again and a whole different race of creatures might have evolved from a progenitor like Cynognathus. Dinosaurs might never have existed, and the first humans might have evolved way back in the Mesozoic Era rather than 60 million years later!
Finally, speaking of mammals, it's more than a little ironic that the dinosaurs owed their tens of millions of years of dominance to the Permian Extinction--because the dinosaurs themselves were wiped out by the K/T Extinction event 65 million years ago, which opened the door for the small, shrew-like mammals that survived to evolve (eventually) into the plus-sized megafauna mammals of the Cenozoic Era, and then into modern humans.