There are several stories but basically all go like this..
One day Ganeshji had eaten a lot of ladus and decided to go on a ride on his mouse. A snake crossed their path and frightened mouse caused Ganeshji to fall down. The fall caused Ganeshji's stomach to burst open. Ganeshji hurriedly collected all the ladus and put them back in his stomach and then tied the snake around his waist.
Moon upon seeing this whole incident laughed at Ganeshji, Ganeshji got angry and hurled his tusk at the moon, alternatively he caused the moon to disappear and then reappear. (Explanation of the craters on the moon/ waxing and waving of the moon). And he cursed that anyone who would look at the moon on Ganesh Chaturthi would be accused of theft.
There are 2 remedies for looking at the moon
1. To throw rocks at the moon while keeping the head down and urging Lord Ganesha to save oneself from the blight
2. Reciting the episode of the
Syamantaka jewel; in which Krishna too was accused of theft for looking at the moon on Ganesh Chaturthi.