Set, sometimes spelled Seth, is a deity found in the mythology of ancient Egypt usually depicted as the traitor among the Egyptian gods, his official titles are the god of chaos, desert, storms and foreigners. Originally Set was held in high regard due to his status a desert divinity but over the course of time would become increasingly negative until he became the demonic figure he is recognized as in modern mythology.
Set, was not originally the prime evil figure in Egyptian mythology, as that title belongs to Apep, the evil god of darkness. Apep fought against Ra, God of light, and Set was one of the gods who fought against him to protect Ra, giving him a similarity to the figure of Lucifer in Christianity who was an angel who fell from grace and became the Devil. Set becomes the antagonist in the Osiris myth, where he opposes his brother Osiris, who symbolized order, and his nephew Horus. While the Apep-Ra conflict was a depiction of the battle between light and darkness, the Set-Osiris/Horus depicted the battle between order and chaos.
Already associated with the uncertainties and hardships of the open desert, he had a bad, but not ignoble reputation. Due to Set's ties with his mortal enemy Apep, the two became ironically intertwined. Because of this, especially in the western world, conceptions of Set began to take on the serpentine features of Apep. This is further confounded by the inability of archeologists to identify a specific animal-form to Set, so instead the label "Typhonic" was adopted, like-Typhon of Greek mythology, which is to say of many forms, primeval, and generically serpentine. It is not impossible to see how it was Set became likened to serpents, even while no such relationship exists. It is even possible because Set's animal-head often adorns staves, the long slender snake-like shape of a staff was attributed to Set, such as when Moses transmutes a staff into a snake in the Old Testament.
Set was born from the earth god Geb and the sky goddess Nut, along with his twin-sister Nephtys, who also became his wife. Nut and Geb also gave birth to the twins Osiris and Isis, who became the king and queen of Egypt. Set became jealous of his brother, and sought to usurp his throne. He eventually killed Osiris and dismembered him, spreading his corpse parts around Egypt. Isis, with the help of Nephtys, sougth to collect the parts of his husband's corpse, while Set became king. The two goddesses collect all parts, and, with the help of Thoth and Anubis, they resurrect Osiris for a brief period, enough for Isis to conceive their son, Horus.
Isis hides along with her son, so that she can raise him while protecting him from Set. Horus eventually reaches adulthood, and challenges Set for the throne. Their struggle drags for eight years, but Horus prevails. Set attempts to rape Horus after his defeat but Horus castrates him, while Set removes Horus eyes. At this moment Thoth steps in to mediate the conflict, restoring the two and declaring Set's defeat. As the conflict ends, the two deities reconcile, as Horus rules over the fertile regions of Nile while Set is given rule over the desert and the foreign lands. Horus finally reclaims the throne as the rightful king of Egypt, and gives his father Osiris a proper funeral, restoring him in his afterlife, as Osiris becomes ruler of the dead.
After this story came into circulation, the role of Apep was largely morphed into Set.