A Mastering Engineer prepares audio so that it sounds as good as possible for the (rang of) format(s) it will be published on.
Mastering Engineers general use hardware or software audio-signal processors like EQs, compressor and limiters to optimize the sound as they see needed. Experience is key in getting a loud yet dynamic end result.
While more and more producers can do some mastering in their own studio using software tools like iZotope Ozone or Waves plugins, to get a pro sounding track a Mastering Engineer’s high-end equipment, extensive and dedicated experience combined with a fresh pair of ears often give a real pro touch to tracks.
Many Mastering Engineers produce music themselves as well and often offer production and / or mixing services as well.