Although many people believe that the earth was created, for the sake of this article, I am going to present a brief sketch of the prevailing scientific thought on the subject.
The earth began as a part of a cloud of gas and debris.
Sometime after the cosmos began generating stars and galaxies, a huge amount of hydrogen gas began to build itself into a dense ball. Over time, the gravitational forces within the cloud became so great that enormous amounts of pressure built up inside the orb creating a giant fusion generator. The energy and heat created by the fusing of hydrogen atoms to produce mostly helium atoms switched on the sun. At the same time, vast amounts of leftover debris were flung out into space in relatively flat pattern around the newly lit sun.
Gravity kept the now distant gases and debris from escaping the solar system.
Because of the swirling effect left from the gases as they were sucked into the disk of the sun, this debris began to orbit around the young star. Pieces of rock in various sizes began to bump and grind and crash into each other. As they did, a small bumpy planet began to take shape. As it grew and developed its own gravitational pull, more and more chunks began to crash into its surface. This created a larger and larger ball.
To be classified as a planet, a body must be able to clear out everything else from its orbit.
Over the eons, the earth began to complete the process of clearing all of the smaller pieces of space rock from its relatively well-formed orbit. Current thought holds that a second planet only slightly smaller than the young earth crashed into it. Much of the second planet was incorporated into the earth's mass. However, a piece of considerable size spun off into an orbit about the planet and eventually was fashioned into the moon.
The earth became a collector of water.
Since water occupies a number space objects like comets, over time either the water that was already a part of the pieces that came to comprise the earth or water left in space by passing bodies was pulled down to the planet. This slowly but surely became the water that covers 3/4 of the planet's surface today. Of course, the good news is that the earth formed at approximately 93,000,000 miles from the sun. This is precisely the distance needed to keep water as a liquid on the planet. With large amounts of liquid water and warm surface, life had a perfect place to happen and survive.