From wiki:
Pre-solar nebula
The nebular hypothesis maintains that the Solar System formed from the gravitational collapse of a fragment of a giant molecular cloud which likely was several light-years across. Until a few decades ago, the conventional view was that the Sun formed in relative isolation, but studies of ancient meteorites reveal traces of short-lived isotopes such as iron-60 which only form in exploding, short-lived stars. This indicates that a number of supernovae occurred near the Sun while it was forming. A shock wave from one of these supernovae may have triggered the formation of the Sun by creating regions of over-density within the cloud, causing these regions to collapse. Because only massive, short-lived stars produce supernovae, the Sun must have formed in a large star-forming region which produced massive stars, possibly similar to the Orion nebula.
One of these regions of collapsing gas (known as the pre-solar nebula) would form what became the Solar System. This region had a diameter of between 7000 and 20,000 astronomical units (AU) and a mass just over that of the Sun. Its composition was about the same as that of the Sun today, with Hydrogen, along with helium and trace amounts of lithium produced by Big Bang nucleosynthesis, forming about 98% of its mass. The remaining 2% of the mass consisted of heavier elements that were created by nucleosynthesis in earlier generations of stars. Late in the life of these stars, they ejected heavier elements into the interstellar medium.
Because of the conservation of angular momentum, the nebula spun faster as it collapsed. As the material within the nebula condensed, the atoms within it began to collide with increasing frequency, converting their kinetic energy into heat. The center, where most of the mass collected, became increasingly hotter than the surrounding disc. Over about 100,000 years, the competing forces of gravity, gas pressure, magnetic fields, and rotation caused the contracting nebula to flatten into a spinning protoplanetary disc with a diameter of ~200 AU and form a hot, dense protostar (a star in which hydrogen fusion has not yet begun) at the center.
At this point in its evolution, the Sun is believed to have been a T Tauri star. Studies of T Tauri stars show that they are often accompanied by discs of pre-planetary matter with masses of 0.001–0.1 solar masses. These discs extend to several hundred AU—the Hubble Space Telescope has observed protoplanetary discs of up to 1000 AU in diameter in star-forming regions such as the Orion Nebula—and are rather cool, reaching only a thousand kelvins at their hottest. Within 50 million years, the temperature and pressure at the core of the Sun became so great that its hydrogen began to fuse, creating an internal source of energy which countered the force of gravitational contraction until hydrostatic equilibrium was achieved. This marked the Sun's entry into the prime phase of its life, known as the main sequence. Main sequence stars are those which derive their energy from the fusion of hydrogen into helium in their cores. The Sun remains a main sequence star today.
Formation of planets
The various planets are thought to have formed from the solar nebula, the disc-shaped cloud of gas and dust left over from the Sun's formation. The currently accepted method by which the planets formed is known as accretion, in which the planets began as dust grains in orbit around the central protostar. Through direct contact, these grains formed into clumps between one and ten kilometres (km) in diameter, which in turn collided to form larger bodies (planetesimals) of ~5 km in size. These gradually increased through further collisions, growing at the rate of centimetres per year over the course of the next few million years.
The inner Solar System, the region of the Solar System inside 4 AU, was too warm for volatile molecules like water and methane to condense, so the planetesimals which formed there could only form from compounds with high melting points, such as metals (like iron, nickel, and aluminium) and rocky silicates. These rocky bodies would become the terrestrial planets (Mercury, Venus, Earth, and Mars). These compounds are quite rare in the universe, comprising only 0.6% of the mass of the nebula, so the terrestrial planets could not grow very large. The terrestrial embryos grew to about 0.05 Earth masses and ceased accumulating matter about 100,000 years after the formation of the Sun; subsequent collisions and mergers between these planet-sized bodies allowed terrestrial planets to grow to their present sizes.
I'm not an atheist, BTW.