The Mammal-like Reptiles, or Therapsids first appeared about 285 million years ago near the begiining of the Permian which is well before the dinosaurs. They evolved quickly and many different groups arose. They were very successful until about the end of the Permian, about 245 million years ago, when something catastrophic affected the earth and nearly all of the species then living died out. New species evolved rapidly to fill this empty habitat, among them the first dinosaurs and a few million years later the first mammals.
The first mammal may never be known, but the Genus Morganucodon and in particular Morganucodon watsoni, a 2-3 cm (1 inch) long weasel-like animal whose fossils were first found in caves in Wales and around Bristol (UK), but later unearthed in China, India , North America, South Africa and Western Europe is a possible contender. It is believed to be between 200 MYA and 210 MYA. However Gondwanadon tapani reported from India on the basis of a single tooth in 1994 may be an earlier contender for the title, with a claimed date of 225 MYA.
Early amniotes split into two groups: the sauropsids and the synapsids. The sauropsids have evolved into modern birds and reptiles, and synapsids have evolved into modern mammals. Synapsids split into various groups, one of which was the therapsids. All living mammals do come from therapsids, but synapsids are considered the common ancestor or mammals.