The story of how Mjöllnir came into existence is told in the tale of The Creation of Thor’s Hammer. To briefly summarize:
One day, the trickster Loki was feeling especially “tricksy,” and cut off the long, golden hair of Thor’s wife, Sif. Enraged, Thor was about to kill Loki when the latter swore to go down to Svartalfheim, the land of the dwarves, who were renowned as the greatest smiths in all of the Nine Worlds. There he would obtain a head of hair for Sif that was even more marvelous than the one he had lopped off. Thor consented to this plea bargain.
While in the cavernous smithies of the dwarves, Loki was able to acquire his prize, and, by cunningly challenging several dwarves to prove who was the best smith, he acquired several more treasures for the gods as well. Among these was Thor’s hammer, which was short in the handle because Loki, in the form of a fly, bit the eyelid of the dwarf who was forging it.
When Thor saw the hammer, the finest weapon in the universe despite its flaw, he agreed to let Loki live.