The Sun and the planets formed together, 4.6 billion years ago, from a cloud of gas and dust called the solar nebula. 
Page 4#
A shock wave from a nearby supernova explosion probably initiated the collapse of the solar nebula. 
Page 5#
The Sun formed in the center, and the planets formed in a thin disk orbiting around it.
Page 6#
In a similar manner, moons formed orbiting the gas giant planets
Comets condensed in the outer solar system, and many of them were thrown out to great distances by close gravitational encounters with the giant planets. 
After the Sun ignited, a strong solar wind cleared the system of gas and dust. The asteroids represent the rocky debris that remained.