The key can be obtained by completing the following questline (Starts just outside Karazhan, with Archmage Alturus, an Archmage of the The Violet Eye (46,75)):
 Archmage Alturus: Lower City; optional talk to NPC, 5 rep with Violet Eye
 Arcane Disturbances: Deadwind Pass; standard soloable exploration quest
 Restless Activity: Deadwind Pass; standard soloable kill quest, can be done at the same time as above
 Contact from Dalaran: Dalaran; talk to NPC
 Khadgar: Talk with Khadgar in Shattrath City
 Entry Into Karazhan: Dungeon; first key part to be found in the Shadow Labyrinth, Auchindoun
 The Second and Third Fragments: Two dungeons; the second key part is found in The Steamvault and the third key part is found in Arcatraz
 The Master's Touch: Dungeon; Talk with Medivh in the Opening the Dark Portal (Black Morass) instance in Caverns of Time. He'll give you his own key.
 Return to Khadgar: Soloable; just return to Khadgar
The whole questline rewards 2100 reputation with the Violet Eye. Before patch 2.4, that fact could be used to look up if someone has The Master's Key in the Armory. Now that a player can enter Karazhan without the key, it can't be used anymore.