It required some serious luck:
The atmosphere that we take for granted is a relatively recent thing. In particular, it took billions of years of organisms turning sunlight, carbon dioxide and water into carbohydrates — an energy source that could be used even in the absence of sunlight — which produced oxygen as a by-product. At first, this trace amount of oxygen was absorbed by the oceans or by the seabed rock. Once the oxygen began to make its way out of the oceans, it was absorbed by the land surface. Finally, the oxygen accumulated in the atmosphere, paving the way for life as we know it.
Some perspective on the scope of human history:
About 83 million years separated Apatosaurus from Tyrannosaurus and Allosaurus from Triceratops. The so-called Age of Mammals—which began when the non-avian dinosaurs were wiped out—has been going on for about 66 million years. Less time separates us from Tyrannosaurus rex than separated T. rex from Stegosaurus.
(Video: A mashup of Carl Sagan narrating the creation scene from Tree of Life)