The answer by Gijsv is correct, but maybe one should add about black body radiation.
It has a specific spectrum and intensity that depends only on the body's temperature, which is assumed for the sake of calculations and theory to be uniform and constant.
It has been observed that all bodies radiate electromagnetic radiation according to the formula given in Gijsv's answer.
It is because all matter is made up of atoms and atoms have charges and magnetic and electric distributions . Atoms hitting each other do not just bounce, exchanging energy , but also, due to the electric and magnetic fields also radiate away some of the energy until they reach an equilibrium.
In the core of the sun, the atoms are ionized, it is a soup of electrons and ions, so the electric fields are strong . The helium and neutrons(neutron has a magnetic moment) of the fusion reaction hit around and lose their kinetic energy in interacting with the electric and magnetic fields of each other, emitting photons, until they come into equilibrium with the surrounding soup .
The sun energy production is a complicated story, but the rough description holds.