The sun doesn't exactly "create" energy. We should be careful to remember the law of conservation of energy: energy and matter cannot be created or destroyed. However, they can be "converted" from one into the other via E=MC2. This is what would take place in an antimatter reaction. However, nuclear reactions are a bit different.
At quantum levels, the difference between matter, mass and energy get a bit blurry. To say that the product nuclei of a fusion reaction have less total mass than the reactant nuclei is not to say that the masses of the protons and neutrons themselves are changing. Rather, the energies binding them together are being adjusted as the constituents of the nucleus change. These energies actually contribute to the mass as well.
Mind that the difference in mass is incredibly small, and the energy output of a single hydrogen-hydrogen fusion reaction is very weak in terms of human scales of energy.
The Sun produces heat in its core through the process of nuclear fusion.
"Nuclear fusion is the process by which two light atomic nuclei combine to form one heavier atomic nucleus. As an example, a proton and a neutron can be made to combine with each other to form a single particle called a deuteron."
'In general, the mass of the heavier product nucleus (the deuteron, for example) is less than the total mass of the two lighter nuclei (the proton and the neutron)."
"Nuclear fusion take place in the Sun's core and it is in this region that the bulk of the Sun's production of energy, heat, and gamma rays takes place."
For more information about the Sun's production of energy through nuclear fusion, click on the links below.
Sun creates energy by nuclear fusions which happens in the core. There is fusion of hydrogen and helium nuclei. And that is how, the mighty sun produces its energy.
By nuclear fusion.