The story of Ganesha and Chandra
In a popular telling, Ganesha had eaten generously after receiving offerings from devotees. While traveling, he stumbled and the Moon, Chandra, laughed at his appearance. Ganesha rebuked the Moon for pride and vanity and pronounced a curse connected with looking at the Moon on the fourth lunar day.
When Chandra realized the seriousness of the curse, he sought forgiveness. The curse was then moderated rather than simply erased. This is used to explain why devotees avoid moon-viewing on Ganesh Chaturthi and why the custom focuses on a particular lunar period rather than every night.
