The Sun is a big ball of relatively dense gas. At most points within the Sun, if a photon is emitted, it will be re-absorbed or scattered on a relatively short length scale.
The photosphere of the Sun (what we can actually see) is simply defined as that surface at which a photon that is emitted outwards will most likely escape. This is also the definition of transparency!
In other words, what lies above the photosphere is transparent to the radiation emitted at the photosphere.
This definition is inexact in the sense that one can only define a probability that a photon will escape. By convention, the photosphere is usually defined to be where the optical depth is approximately 2/3 and a photon has about a 50% chance of escaping. This in turn is wavelength dependent (since the absorption coefficient of the gas in the Sun's atmosphere varies with wavelength) and this is why we see features and absorption lines in the solar spectrum - we are viewing to different depths (and hence temperatures) into the Sun.
The reason that the photosphere is at this particular density/temperature, is that the opacity at the photosphere and just below is dominated by H$^{-}$ ions. These are formed from the copious H atoms combining with free electrons from easily-ionised heavier elements like Na, Fe, Mg etc. These H$^{-}$ ions can then easily be disintegrated by any photon with energy more than about 0.75 eV leading to opaqueness to light with $\lambda < 2.2\,\mu$m. However, as the density/temperature decreases with height it becomes increasingly difficult to form H$^{-}$ ions because the supply of free electrons dries up, collisonal timescales increase, and the gas becomes transparent to visible light, except at distinct wavelengths corresponding to absorption lines of various chemical species.
If you like you can turn this around and ask yourself - if I fired a photon at the Sun, at what position in the Sun's atmosphere would it most likely be absorbed? The answer is the photosphere, the depth at which the Sun ceases to be transparent.
NB: The chromosphere and corona lie above the photosphere, are hotter but much less dense, and are transparent to visible light of almost all wavelengths. They too emit light, mostly in the form of narrow emission lines with very little continuum. The light from the photosphere below usually swamps our view of the chromosphere, however it can be seen above the limb of the Sun during a solar eclipse and high resolution spectroscopy can detect the chromospheric emission lines, especially in the ultra-violet and EUV regions where it dominates.