Absorption spectra are a result of light of a certain wavelength exciting an atom from a lower energy level to a higher one and at the same time being absorbed. However, the atom should eventually go back down to its lower energy state, and at the same time emit a photon of same frequency it absorbed earlier. Overall, no changes to the star's spectrum should occur.
When the energy level drops and the photon is re-emitted, it is scattered or re-emitted in a random direction, so less of that frequency reaches your telescope/spectroscope. It is sort of analogous to the "why is the sky blue" question. What you are looking at is direct line photons(line of sight), so photons passing through the star's gaseous layers are depleted in this line of sight by the random scattering.
A similar explanation, is that the intensity at any given frequency is the optical depth weighted average of the plank (black body) function. As the light ray goes deeper (maybe comes from deeper down is more intuitive) for each delta in optical depth the local temperature determines the ratio of emission to absorption. In the center of an absorption line, the opacity is higher, and thus the depth in the photosphere for a given optical depth is less than it is outside of the line. Since in the photosphere, temperature decreases with height, the spectral lines reflect a lower emission temperature. A more intuitive, but less exact way to think of it, is to consider the beam of light to be formed at an optical depth of unity. In the center of an absortion line, that depth is much less, so the strength of the plank function is much lower (reflecting the lower temperature higher up in the stellar atmosphere).
For very very strong lines, you can get the opposite effect -emission lines, as the temperature in the stars chromosphere and corona increase with height, and the closer to the line center you are the higher the effective height of formation.
Stars have plenty of "cold" gas (atoms in their ground states). If you put some gas on the way from a light source to you, some frequencies will be less represented (dark absorption lines) than non resonance frequencies. Atoms for such frequencies are like a fog on the light way - they capture and diffuse the resonance frequencies to the whole solid angle $4\pi$. So you observe them as less represented than the neighboring non resonance frequencies in the continuous spectrum.