The solar system formed from a cloud of interstellar gas around 4.6 billion years ago. At some point, this cloud collapsed under gravity and the sun formed. The pressure in the center became so high that hydrogen atoms began fusing into helium, and the nuclear reactions that power stars begun. A solar nebula of gas began rotating around the Sun. From clumps of material in this disk, planets and Moons were formed. The exact process is a bit more complicated and there are three contrasting theories about the formation of our solar system. Let’s look at some of the details.

The first model, which is referenced in most sources is called the core accretion model. It means that the cloud of gas collapsed under gravity to form the Sun. The gravitational potential energy was converted into thermal energy in the center of the solar system, which ignited nuclear fusion on our star. The solar wind swept lighter elements, such as hydrogen and helium from the inner regions of the solar system, leaving only rocks and minerals. Further away, the cooler temperature and the presence of hydrogen and helium allowed the gas giants to form, and their icy moons. This model makes sense when looking at our solar system, Mercury, Venus, Earth and Mars are rocky planets, Jupiter, Saturn, Uranus and Neptune are gas giants.
The most evidence for this model comes from looking at exoplanets. Stars with a greater proportion of elements other than helium and hydrogen have more giant gas planets in their planetary systems. Furthermore, the discovery of HD 149026, a star around which a giant planet was found, supported this hypothesis. It suggests that there should be more rocky planets than gas giants, which makes one optimistic about the search for extraterrestrial life.
Nonetheless, there are two major issues with the accretion model. Firstly, the tiny rocky planets during formation should have fallen into the Sun before reaching a stable orbit. Secondly, the gas giants would not have enough time to complete formation, before all of the gas would be swept away by solar wind. This discrepancy is on the order of several million years. To address these limitations, scientists have developed the disk instability model.

This model states that clumps of gas were already forming in the earliest stages of the solar system’s life. This allowed them to create stronger gravitational field and trap the escaping gases. They were able to reach the critical mass to become a planet in as little as 1000 years, which is a blink of an eye on the cosmic scale.
The third model is pebble accretion, which has gained traction this decade. It differs from the previous two models by stating that the planets formed even faster, by collecting smaller fragments of other bodies that were forming. The main issue in these models is time, and it seems that formation of planets from a collection of small pebbles would achieve this the fastest. The best theory will be verified with more precise computer simulations and exoplanet observations, as telescope technology improves.
Let’s end this discussion with examining how the solar system continued forming. Especially, how did Earth get its immense amount of water? The mainstream theories for a long time claimed that water came from comets, since the Earth was too warm to accrete ice from the gas cloud. However, flybys of the Halley’s comet and the Rosetta satellite showed that the ice composition on these bodies is different than ice on Earth. Another potential source remains asteroids from the asteroid belt, yet that claim still remains to be verified. In accord with pebble accretion, another theory states that the Earth formed quickly enough that it could accrete water molecules before it was too hot. As you can see, the formation of the solar system is closely linked with other mysteries of life.
References
Czekala, I. (2011, March 11). Review Article: Protoplanetary Disks and Their Evolution. Astrobites. https://astrobites.org/2011/03/11/review-article-protoplanetary-disks-and-their-evolution/
Dherna98, A. (2017, May 6). How solar system was formed. Joliet Junior College – Astronomy 101 Class Blog. https://jjcastronomy.wordpress.com/2017/05/01/how-solar-system-was-formed/
Our Solar System. (n.d.). NASA Solar System Exploration. https://solarsystem.nasa.gov/solar-system/our-solar-system/in-depth/
Savagekt, S. (2014). disk instability. Planet Hunters. https://blog.planethunters.org/tag/disk-instability/
Tillman, N. T. (2017, February 1). How Did the Solar System Form? Space.Com. https://www.space.com/35526-solar-system-formation.html