Atlas was a leader of the Titans in their war against Zeus and after their defeat he was condemned to carry the heavens upon his shoulders. According to others he was instead (or later) appointed guardian of the pillars which held the earth and sky asunder. Atlas was also the god who instructed mankind in the art of astronomy, a tool which was used by sailors in navigation and farmers in measuring the seasons. These roles were often combined and Atlas becomes the god who turns the heaven on their axis, causing the stars to revolve.
During the Titanomachy with the titans and Gods fighting against each other, Atlas sided with the titans and became the general of the titans. Because of this, after the Gods beat the titans, they were all given a punishment (other than Prometheus and Epimetheus who sided with the Gods). Most of the titans were locked in Tartarus but because Atlas was the general of the titans he was given the duty to hold the sky from the Earth. Zeus placed him to the most western point on Earth and left him there to handle his punishment.
One day the hero Heracles came to finish his eleventh labor. The labor was to pick a golden apple from the Garden of the Hesperides. He passed Atlas, and offered to take the sky for a few moments so that Atlas could travel to the Hesperides, who were his daughters, and return to Heracles with a golden apple. Atlas agreed, and gave the weight of the sky to Heracles. He held it while Atlas stretched and walked off. He came back, holding a golden apple, and said he would take it and do Herakles's job and take the glory for himself. He was stopped, and Herakles asked if Atlas would take the sky for a moment so he could put a covering on his shoulders to lighten the burden. Atlas set the apple down and took the weight of the sky back from Heracles. Heracles then took the apple and left Atlas to endure his burden.