As per Hindu Epic Ramayana, When Hanuman went to the Lanka in search of Sita mata (Wife of Lord Rama). After meeting with Sita mata, when Hanumanji was coming back, he met with many God who were in clutch of Rakshash (Evil) King Ravan. God Shanidev was also there. Hanumanji helped freeing shanidev and getting out of Lanka. Because of Hanumanji helped Shanidev they both became friends. Here, Shanidev Promised to Hanuman that anyone who prayed to him (Hanuman), he would be rescued from the baleful effects of Shanidev.Other story of Shanidev and Hanumanji : God Surya Dev is the Father of Shanidev. Surya dev is also the Guru (Teacher) of Hanumanji. After the completion of course, Surya dev said to Hanuman, “You have become adept in all forms of wisdom and weapons, now go to your mother Anjani” But Hanumanji requested to Surya dev “Give me an opportunity to repay for your tutelage” Suryadev said to Hanuman, “my wayward son shani is the cause of my sorrow only, Go and bring that wayward son of mine back to me”.