Which came first: the sun or the earth?

The sun came first before the Earth. To understand this, you can look at the process of how planets form in our solar system.

Around 4.6 billion years ago, a vast cloud of gas and dust known as the solar nebula began to collapse under its own gravity. As the collapse occurred, most of the material collected at the center, forming the Sun. The intense gravitational forces at the core of the collapsing cloud caused the temperature and pressure to rise, triggering nuclear fusion, which gave birth to a star - the Sun.

As the Sun formed at the center, the remaining material in the cloud began to spin around it, forming a rotating disk called the protoplanetary disk. Within this disk, smaller clumps of material called planetesimals started to form due to the gravitational attraction between particles. Over time, these planetesimals collided and merged, gradually growing larger and becoming protoplanets.

One of these protoplanets was Earth. It took millions of years for the protoplanet Earth to accrete enough material and undergo various processes like differentiation and cooling to become the planet we know today.

In summary, the Sun formed first in the early stages of our solar system's formation, while the Earth formed later from the remaining material in the protoplanetary disk around the Sun.