For the first few million years of its life, the Sun was a large red star surrounded by a disk of gas and dust—the primitive solar nebula—that reached out beyond the boundaries of our present planetary system. Like all stars, the Sun was created by the collapse of a cold, dense core within a rotating cloud of interstellar material, debris from supernovae and other evolved stars of a previous generation. Angular momentum in the cloud allowed collapse along only one axis, thus leaving the material in a thin orbital plane around the new Sun. During the next hundred thousand years, the dust began to coagulate into larger particles, which eventually became planetesimals, the seeds for the nine planets. Over a further 10 million years, these planetesimals grew larger, clearing the residual gas and dust by dynamical sweeping and gravitational capture. Collisions led to further growth and the creation of a system of planets, comets and asteroids orbiting the young Sun. Within a billion years, the first life came into existence on one of those planets. Now, 5 billion years later, that life has developed to a degree of sophistication that seemingly defies the second law of thermodynamics.
Planet formation used to be a subject for speculative natural history. Now it is an active field of observational astronomy, and the evidence is that planetary systems are abundant.