Moon is the sun of Saptarishi Attri and Mata Anusuiya. He is married with two daughters of Prajapati Daksha. They are Revati and Rohini.
Daksha Cursed Moon
Moon loved Rohini more. Revati was just a burden for him. She complained about it with his father. Prajapati Daksha got furious and as a king he asked Moon to give equal respect and love to both of his wives. Moon refused and insulted Revati.
Daksha, being a father and king, cursed moon to decay till death. Immediately Moon went into deep coma.
Brahma dev shouted at Daksha for cursing a planetary object without which the whole system could disturb. Daksha assured Brahma that he will create another planet to replace Moon.
Use of Mahamrityunjaya Mantra
Saptarishi came to Rishi Attri and informed him about Rishi Markandeya, who practiced and created the Mahamrityunjaya Mantra and saved himself from death. The same mantra could save Moon too.
All the Saptarishi went to meet Markandeya and informed him about the incidence. Markandeya got ready to share his Mahamrityunjaya Mantra but a problem was still there. Daksha already cursed Shiva that He won’t be worshiped (Why Daksha Cursed Shiva?). So without worshiping Shiva, the mantra wouldn’t work.
Narayana and Brahma Lifted Shiva’s Curse
Daksha cursed Shiva when He was separated from Adi Shakti. So Narayana found a loop hole and got the way to lift the curse. He informed Brahma Dev that Sati could be worshiped because the curse was on Shiva only.
Shiva and Shakti are both the part of same power. So worshiping Shakti will lead to worshiping Shiva and if it completed successfully then curse will automatically get lifted.
According to the plan, Narayana and Brahma disguised themselves as sages and asked Sati to carry Shiva Linga and let them worship it.
Sati thought she was helping the sages but in reality Narayana and Brahma was worshiping Sati only. As soon as their prayer completed, Shiva got free from the curse.
Foundation of Somnath Jyotirlinga
To save Moon, all saptarishi and other sages started chanting Mahamrityunjaya Mantra. While Moon was on the verge of complete decay.
Shiva appeared and healed the Moon. Although the curse of Moon wasn’t lifted completely. Shiva supported the decision of Prajapati Daksha of punishing Moon because he did wrong with Revati. Moon apologized for his mistake and promised to give equal respect to both his wives.
Shiva then blessed Moon by giving him position on His crest. Due to the curse of Daksha, Moon decays for 15 days of the month and due to the blessings of Shiva, it grows for the next 15 days.
Shiva also blessed the place with his energies. It is known as Somnath Jyotirlinga.