The sun's energy comes from the nuclear fusion reactions that happen within its core. When atoms of hydrogen come together in the core of the sun, they fuse to become another element: helium. This reaction produces energy.
The fusion of hydrogen atoms into helium releases energy because the mass of helium formed is slightly less than the mass of the original hydrogen atoms. This extra mass is converted into energy. Einstein's equation E = mc^2 depicts this energy-releasing process.
The energy radiating outward balances the gravitational force wanting to crush the sun. Only under conditions of extreme temperature and pressure, such as those found within the core of the sun, can nuclear fusion reactions happen. Once all the hydrogen atoms in the sun's core are fused into helium atoms, the star begins to die.