During mastering, the mixed material is processed so that it sounds great in as many different listening environments as possible
The mastering engineer tempers or eliminates any issues the mix engineer may have created that would be detrimental to the final version of the track. They can also creatively enhance elements in the mix. They maximize loudness to help your track in competitive noise environments and also make sure that the different songs on an album are all brought up to similar levels. Once complete, they create the media (CD, DDP, WAV file, etc) that will be used for replication, duplication, and/or digital distribution.
Even though I master things occasionally, I am not an experienced mastering engineer. The art that is mastering takes years of experience and often specialized gear and plugins to become proficient.
Here are their takes on mastering. Thanks guys for sharing your expertise!
Dave Sperandio: 5 Reasons Your Music Needs Mastering
Bill Hare: What is Mastering? Song: Es War Gut So performed by Maybebop