Our solar system formed about 5 billion years ago from an enormous cloud of dust and gas, a nebula. Dense parts of the clouds underwent gravitational collapse and compression to form a rotating gas globule, and then a disk. After further collapse, it eventually coalesced into a Sun together with orbiting planets, asteroids, etc.
The Sun has used up about half of its nuclear fuel; it will begin to die in another 5 billion years. It will eventually become a cold, black dwarf.