Our Sun was formed from a huge cloud of dust and gas called a nebula. Gravity pulled the dust and gas together, so the cloud shrank. As it shrank, gravitational energy was transferred to thermal energy, and the temperature and pressure at its centre rose.
When the core became hot and dense enough, hydrogen nuclei began to join together to form helium nuclei. This is nuclear fusion, and it releases a large amount of energy. The new star began to shine.
The Sun is now stable. Gravity pulls inwards and tries to make the Sun collapse. The energy released by fusion heats the gas and makes it push outwards. The two effects are balanced, so there is an equilibrium and the Sun stays the same size. If fusion released less energy, the outward push would be weaker than gravity and the star would shrink. The Sun is a star, and it stays stable for as long as it has hydrogen to fuse.