Hi,
We think the Sun and the rest of of the solar system were created from a big cloud of gas and dust left over from earlier stars that exploded in a supernova. Something, maybe a shock wave from another exploding star, caused that cloud to be compressed enough so that it was dense enough to forma a star, our sun. This happened over 4.5 billion years ago - a very, very long time.
There is more about how the solar system formed here:
https://spaceplace.nasa.g...system-formation/en/ Terry