Mastering is both the last stage of production and the first stage of manufacturing. It is the last chance to alter the sonic presentation and is where the various parts of an album are brought together into a cohesive whole.
The mastering room provides a different (hopefully accurate) monitoring situation and a set of fresh (hopefully experienced) ears to help the artist and producer achieve their vision for the final record.
Some of the processes that might be involved:
Many will add to these things like compression and/or (for digital recordings) "normalization".
Personally, while I can see compression as an effect on individual tracks of a multitrack (e.g. to get Ringo's cymbal sound), I don't at all like its use on whole mixes where it is generally used to achieve more loudness (some say "punch" but how do you increase punch by taking away dynamics, where the punch lives?).
This is a subject about which much can be and has been written. Many mastering engineers today "compete" on the basis of how loud they make records. A good number of record producers and A&R folks still seem to think we buy records because they are loud and not because we like the music. (Go figure.) From my perspective, all the best sounding recordings I have heard have in common the fact that they are not loud. Having loudness as a goal necessitates the sacrifice of dynamics which is something I'd prefer not to do.
"Normalization" (I call it abnormalization) is a means of raising the level of a digital recording so the peaks reach maximum level. This is a trap many semi-pros (among others) fall into. When done for an album project, it results in "quiet" tunes that sound louder than the "loud" tunes. In addition, when done to a 16 bit recording, as is often the case, this results in truncation of the low order bits (which carry a lot of important musical information), adding harshness and obliterating the stereo image by losing important spatial cues.
So in sum, mastering is where the "part" used for replication is created. It is the final step in the creative process.