The Earth and space
Nearly all of the mass in our Solar System is in the Sun. The Sun is very large. Its diameter is over 100 times the Earth's. The Sun is the source of nearly all the energy we receive. For many years, it was a mystery as to where this came from, and this baffled the leading scientists. It is now understood that the nuclear fusion is the energy source. In nuclear fusion hydrogen nuclei are joined together to make helium nuclei. This releases enormous amounts of energy.
hydrogen nucleus + hydrogen nucleus → helium nuclei
In stars larger than our Sun helium nuclei can be fused together to create larger atomic nuclei. As the Earth contains many of these larger atoms, like carbon, oxygen, iron, etc, scientists believe that our Solar System was made from the remains of an earlier star.
As the gas falls together, it gets hot. A star forms when it is hot enough for a nuclear fusion reaction to start. This releases energy, and keeps the star hot. The outward pressure from the expanding hot gases is balanced by the force of the star's gravity. This happened about 5000 million years ago. This is quite recent in the history of the Universe, which is currently believed to be 14,000 million years old.
Gravity pulls smaller amounts of dust and gas together, which form planets in orbit around the star.