Apep (Apepi, Aapep, Apophis) was a demon of the underworld, in the form of a giant water snake. It was believed that he was created when Nit spat into the primeval waters of Nun. He was the enemy of the sun god, trying to stop him as he travelled on his barque through the underworld each night. He was so powerful that little could defeat him, and even then, he was back again the following evening to threaten Ra. He was a demon outside of ma'at, the opposite of order, a demon of darkness and chaos.
Apep was first attested to during the Middle Kingdom, but the New Kingdom texts provide the myths and legends of this demon. During Roman times, Apep's name was thought to mean 'He who was Spat Out'. He was believed to have been created when Nit spat into the waters of Nun, her spittle turning into the giant water snake. This was thought to happen at the start of time, and that he lived in the primeval waters. His name may mean 'Great Snake' (from aah - in words such as 'be great', 'the great', 'greatly'), but the reading is uncertain. (The sound aah was also the word for donkey, animals that were believed to be followers of both Set and Apep. This may be part of an ancient Egyptian pun.)
He was depicted as a giant water snake, almost always shown being pierced by knives or other weapons or under the control of a deity, so his image would not give the demon power. He was thought by the ancient Egyptians to be over 16m long, with skin as hard as flint. His roar was so loud that it shook the underworld. He was called 'Evil Lizard', 'Opponent of Ra', 'Enemy of Ra', 'World Encircler' and 'Serpent of Rebirth'.
It was believed that Apep waited at Bakhu - the mountain of the horizon - to swallow the barque of Ra, or during in the seventh hour of the night. He also could swallow the waters of the celestial river in the underworld, or use his coils as sandbanks, to strand Ra's barque. Serqet also used her magic to protect the barque from Apep, as she had power over snakes, reptiles and poisonous animals. She was also thought to be able to hold Apep's tail. Maahes also protected Ra on the barque, as he protected the pharaoh while in battle. Shu was a defender of the barque, who used spells and magic to protect Ra from the water snake-demon and his followers. He was also thought to be caught or cut by other deities, including Isis, Nit, Sekhmet, Geb and the Sons of Horus.
The Egyptians believed that Shu was the second divine pharaoh, ruling after Ra. Apep's followers, though, plotted against him and attacked the god at his palace in At Nub. Despite defeating them, Shu became diseased due to their corruption, and soon even Shu's own followers revolted against him. Shu then abdicated the throne, allowing his son Geb to rule, and Shu himself returned to the skies.
Neither Shu, Maahes nor Serqet were strong enough to kill Apep. Only a few could kill him - Set boasts that "Every day I slay the enemy of Ra when I stand at the helm of the Barque of Millions of Years, which no other god dare do." He was the only deity who was strong enough to withstand the power of Apep, and to kill the water serpent.