The origin is rooted in the Shiva Purana account of Ganesha's creation. Its public celebration in modern form is associated with the Indian independence movement, popularised in Maharashtra.
According to the Shiva Purana, Goddess Parvati created Ganesha from sandalwood paste to guard her. When Shiva returned and the child stopped him, Shiva severed the head. To console Parvati, Shiva restored life by replacing the head with that of an elephant and made Ganesha his son.
Shiva Purana; regional tradition