Gilgamesh[a] was a historical king of the Sumerian city-state of Uruk, a major hero in ancient Mesopotamian mythology, and the protagonist of the Epic of Gilgamesh, an epic poem written in Akkadian during the late second millennium BC. He probably ruled sometime between 2800 and 2500 BC and was posthumously deified. He became a major figure in Sumerian legends during the Third Dynasty of Ur (c. 2112 – c. 2004 BC). Tales of Gilgamesh's legendary exploits are narrated in five surviving Sumerian poems. The earliest of these is probably Gilgamesh, Enkidu, and the Netherworld, in which Gilgamesh comes to the aid of the goddess Inanna and drives away the creatures infesting her huluppu tree. She gives him two unknown objects called a mikku and a pikku, which he loses. After Enkidu's death, his shade tells Gilgamesh about the bleak conditions in the Underworld. The poem Gilgamesh and Agga describes Gilgamesh's revolt against his overlord King Agga. Other Sumerian poems relate Gilgamesh's defeat of the ogre Huwawa and the Bull of Heaven and a fifth, poorly preserved one apparently describes his death and funeral.
In later Babylonian times, these stories began to be woven into a connected narrative. The standard Akkadian Epic of Gilgamesh was composed by a scribe named Sîn-lēqi-unninni, probably during the Middle Babylonian Period (c. 1600 – c. 1155 BC), based on much older source material. In the epic, Gilgamesh is a demigod of superhuman strength who befriends the wildman Enkidu. Together, they go on adventures, defeating Humbaba (the East Semitic name for Huwawa) and the Bull of Heaven, who, in the epic, is sent to attack them by Ishtar (the East Semitic equivalent of Inanna) after Gilgamesh rejects her offer for him to become her consort. After Enkidu dies of a disease sent as punishment from the gods, Gilgamesh becomes afraid of his own death, and visits the sage Utnapishtim, the survivor of the Great Flood, hoping to find immortality. Gilgamesh repeatedly fails the trials set before him and returns home to Uruk, realizing that immortality is beyond his reach.
Most classical historians agree that the Epic of Gilgamesh exerted substantial influence on both the Iliad and the Odyssey, two epic poems written in ancient Greek during the eighth century BC. The story of Gilgamesh's birth is described in a second-century AD anecdote from On the Nature of Animals by the Greek writer Aelian. Aelian relates that Gilgamesh's grandfather kept his mother under guard to prevent her from becoming pregnant, because he had been told by an oracle that his grandson would overthrow him. She became pregnant and the guards threw the child off a tower, but an eagle rescued him mid-fall and delivered him safely to an orchard, where he was raised by the gardener. The Epic of Gilgamesh was rediscovered in the Library of Ashurbanipal in 1849. After being translated in the early 1870s, it caused widespread controversy due to similarities between portions of it and the Hebrew Bible. Gilgamesh remained mostly obscure until the mid-twentieth century, but, since the late twentieth-century, he has become an increasingly prominent figure in modern culture.