Once upon a time, Parvati was about to go for a bath. But, she wanted someone to guard the house, so that no one would disturb her while bathing. So, she took some sandal paste and moulded a clay boy out of it. She then gave it life and told him to guard the house and to stop anyone if they tried to enter the house. She considered him as her own son and then she went inside to bathe. Later on, Lord Shiva returned home from the Himalayas and was surprised to find this small boy outside his house. As he tried to enter, the boy stopped him from going further into his own house. Lord Shiva got angry on seeing this and he beheaded the boy by using his trident. Parvati came out and to her shock, she found her son dead.
She pleaded with Lord Shiva to bring him back to life, but he said he was helpless. Even though he felt sorry and wanted to do so, he could not do anything as he had used his trident to behead the boy. He then called upon his bull Nandi and told him to go north and bring the head of the first calf he saw which was away from its mother. Nandi went north and soon found an elephant calf which was away from its mother. Nandi brought back the head of the elephant calf and handed it to Lord Shiva. Using his powers of magic, Lord Shiva attached the elephant head to the beheaded body of the boy and brought him back to life. He then named the boy as Ganesha.
But Parvati feared that people would make fun of him and no one would worship him. So Lord Shiva took him to Lord Brahma and the other gods. They blessed him with many boons and said that anyone who does any pooja or ritual would have to worship Ganesha first before proceeding. He is considered as someone who removes all the struggles of his worshippers. This practice continues even today with the followers of even Jainism and Buddhism worshipping him.