Sun Wukong learned many of his magical tricks while serving as a disciple under the Patriarch Subodhi; it was the Patriarch who gave him the name "Wukong" ("aware of emptiness"). (The Patriarch, who by the time they parted ways was certain the monkey would come to a bad end, made him promise never to tell anyone who his teacher was.)
He is invited to the Heavenly Kingdom by the Jade Emperor in the hopes that a promotion and title will make him a little more manageable. He proves to be an incorrigible monkey, however, and soon he is scarfing down the Empress's Peaches of Immortality and popping Lord Lao Tzu's Pills of Indestructability like they were Tic Tacs. Feeling guilty, but not that guilty, he becomes the biggest headache for everybody in heaven. Only with great effort and teamwork are the eminent beings in heaven able to combine forces and stuff him into Lord Lao Tzu's eight-way trigem oven, which is hot enough to reduce anything to cinders. After a good long cook and then some, they lift the lid to peek -- and out jumps Monkey King, completely unharmed apart from some smoke in his eyes.
All other options exhausted, they finally appeal to the Buddha himself, who arrives in an instant from his temple in the West. The Buddha effortlessly defeats Monkey and places him under the mountain of the five elements. There he must remain imprisoned under the rock until he can offer to serve the future Sanzang, the T'ang Priest, who is destined to make the journey to the West to retrieve the Buddhist scriptures for China. The bodhisattva Guanyin helps Sanzang by giving him a magical headband which Sanzang puts on Monkey's head. With a special word Sanzang is able to tighten the band until Monkey cannot bear the pain. In that way he is brought to his true calling as a disciple of Buddha.
For the rest of the epic Sun Wukong faithfully helps the T'ang Priest on his journey to the west. The are joined by Sandy (Sha Wujing) and Pigsy (Zhu Bajie), two other monsters who have been tamed in advance by Guanyin and woven into Sanzang's destiny. The group gets into many scrapes and must learn many Buddhist lessons before they return safely to the T'ang empire with the treasure of the Buddhist scripture. Monkey and the monk are eventually made into buddas while the others are rewared by the udda based on their levels of enlightment.
It is believed that the character Sun Wukong was partly based on Hanuman, the "monkey god" of Hindu described in a book by Xuan Zang. He also bears some similarities to mischievous six year old boys. Sun Wukong became so well-known in China that it was once worshipped by some as a real god!