Lord Shiva was in Mandarachal and Kashi was ruled by a very pious and religious King named Divodas. In his Kingdom every one was very happy and there was all round prosperity. He had reached an understanding with Lord Brahma that as long as he was ruling, Devas and other celestial beings should stay away from Kashi and should not create any disturbance in Kashi.
Lord Brahma more or less agreed to it but on one condition that King Divodas should prove to be himself an excellent and able administrator and all people living in Kashi or visiting Kashi should be treated well in their religious pursuits. The King agreed to it and accordingly gave excellent governance.
Lord Shiva was very upset at being away from Kashi for a long time and he wanted to make King Divodas commit some mistake. Accordingly, he sent sixty four Yoginis to create some disturbance, but they were enthralled by the beauty and serene surroundings of Kashi which appeared to be a part of heaven. They ultimately settled down there.
When the Yoginis failed to return, Lord Shiva sent Lord Surya with instructions to create some disturbance in Kashi so as to defeat King Divodas in his resolve. Lord Surya came to Kashi and disguised himself as an astrologer, a learned scholar, a religious propagator, a businessman, a brahmin etc. But he could not find any fault with any person in Kashi or with the governance of King Divodas. Lord Surya was also very much attracted towards Kashi and the beauty of the city. Lord Surya thought, if he went back to Mandarachal without fulfilling the wishes of Lord Shiva, the latter would get angry.
Lord Surya finally decided to stay in Kashi. He said to himself, disobeying the instructions of Lord Shiva is a sin, but by staying in Kashi and undertaking religious activities, such sins will easily get cleansed. Accordingly Surya created twelve forms of himself which located themselves at various places in Kashi.
Lord Shiva then sent his Shiv Gans (attendants/servitors) who also were enthralled by the beauty of Kashi and decided to stay there. Finally Lord Shiva summoned his son, Lord Ganesha (Vinayak) with the specific mission of creating disturbances in the governance of King Divodas.
Lord Vinayak reached Kashi and disguised as an old astrologer. He made people dream certain events and visited such persons in the morning and influenced them by interpreting the dreams and their effects. He also started interpreting the planetary positions in their horoscopes in such a way which scared them. Thus he compelled many persons flee Kashi.
In due course, he gained entry into the King’s palace and managed to win the confidence of the ladies thereat. As days went by he also succeeded in impressing the Queen who told the King about the greatness of the old astrologer and suggested that the King should pay his respects to him. On getting the King’s permission, the Queen sent for the old astrologer.
The King welcomed the astrologer with all humility and the latter blessed the King as per the usual practice. The King asked the astrologer to predict the future. The astrologer after deep thought, told various things about the King and the kingdom. He also stated that starting from that very day, on the eighteenth day a Brahmin would come and give him (King) some serious advice which should be followed. After saying this the astrologer left.
In some way or the other Vinayak fulfilled his father’s wishes and settled down in Kashi in various different places in different forms.