Today with help of cosmic background radiation and other methods, we are able to trace back the sequence of events, which led to the creation of earth.
13.8 billion years ago, a catalytic event took place. We have named it “Big bang”. We are not certain what exactly caused this event. There are several theories but cannot be conclusively established.
Scientists are still working on this conundrum and hopefully we will have this question answered in next 50 years.
“Big bang” let to sudden stretch in the fabric of space. Due to high intensity, gluons were created which in turn created quarks and quarks created energy.
After point of time (second!), hadron were formed off quarks and universe expanded to billions of kilometers. Then hydrogen atoms were formed and hydrogen gas for formed across the universe
Over next millions of years, hydrogen gas collapsed under gravity to form stars
About 4.6 billion years ago a star bigger then sun was running out of its fuel in its core. Every star acts as a factory to produce elements that we see all around the planet including our body like carbon, iron, nitrogen, helium, etc.
The star fuses and elements in order to create the next element in the periodic table.
Hydrogen is converted to helium, carbon, silicon and so forth but once it reaches up to iron, the core cant further fuse iron anymore so the entire star collapse in a giant explosion we call as supernova
Elements are scattered in the space at epic proportion. Such an event let to the formation of our solar system and earth.
After supernova, over next millions of years the particles and gas settle down and create planets and asteroids.
About 4.5 million years ago such a planet (our earth) collided with another planet of the size of mars in a giant collision, which led to the creation of moon!
Moon since has helped earth by shielding it from all the dangerous antics of the universe and also stabilised the ecology, which in turn gave existence to what we call life.