Finds in the nearby Kadrini cave indicate occupation during the Paleolithic era as far back as 20,000 BC, and archeological evidence shows a port existed at Syedra, south of the modern city, during the Bronze Age around 3,000 BC. A Phoenician language tablet found in the district dates to 625 BC, and the city is specifically mentioned in the 4th-century BC Greek geography manuscript, the periplus of Pseudo-Scylax. The castle rock was likely inhabited under the Hittites and the Achaemenid Empire, and was first fortified in the Hellenistic period following the area's conquest by Alexander the Great. Alexander's successors left the area to Ptolemy I Soter after 323 BC. His dynasty maintained loose control over the mainly Isaurian population, and the port became a popular refuge for Mediterranean pirates. The city resisted Antiochus III the Great of the neighboring Seleucid kingdom in 199 BC, but was loyal to the pirate Diodotus Tryphon when he seized the Seleucid crown from 142 to 138 BC. His rival Antiochus VII Sidetes completed work in 137 BC on a new castle and port, begun under Diodotus.
The Roman Republic fought Cilician pirates in 102 BC, when Marcus Antonius the Orator established a proconsulship in nearby Side, and in 78 BC underServilius Vatia, who moved to control the Isaurian tribes. The period of piracy in Alanya finally ended after the city's incorporation into the Pamphylia province by Pompey in 67 BC, with the Battle of Korakesion fought in the city's harbor. Isaurian banditry remained an issue under the Romans, and the tribes revolted in the fourth and fifth centuries AD, with the largest rebellion being from 404 to 408. After the Roman Empire's collapse and split, the city remained underByzantine influence, becoming a suffragan of Side, in the metropolis of Pamphylia Prima. Islam arrived in the 7th century with Arab raids, which led to the construction of new fortifications. 681 marked the end of a bishopric in Alanya, although St. Peter of Atroa may have taken refuge here from iconoclasticpersecution in the early 9th century. The area fell from Byzantine control after the Battle of Manzikert in 1071 to tribes of Seljuk Turks, only to be returned in 1120 by John II Komnenos.
At the Battle of Köse Dağ in 1242, the Mongol hordes broke the Seljuk hegemony in Anatolia. Alanya was then subject to a series of invasions fromAnatolian beyliks. In 1293, the Karamanid dynasty took control after Mecdüddin Mahmud conquered the city, but their rule was intermittent. Lusignans from Cyprus briefly overturned the then ruling Hamidid Dynasty in 1371. The Karamanids sold the city in 1427 for 5,000 gold coins to the Mamluks of Egypt for a period before General Gedik Ahmed Pasha in 1471 incorporated it into the growing Ottoman Empire. The city was made a capital of a local sanjak in the eyalet of Içel. The Ottomans extended their rule in 1477 when they brought the main shipping trade, lumber, then mostly done by Venetians, under the government monopoly. On September 6, 1608, the city rebuffed a naval attack by the Order of Saint Stephen from the Republic of Venice.
After World War I, Alanya was nominally partitioned in the 1917 Agreement of St.-Jean-de-Maurienne to Italy, before returning to the Turkish Republic in 1923 under the Treaty of Lausanne. Like others in this region, the city suffered heavily following the war and the population exchanges that heralded the Turkish Republic, when many of the city's Christians resettled in Nea Ionia, outside Athens. The Ottoman census of 1893 listed the number ofGreeks in the city at 964 out of a total population of 37,914. Tourism in the region started among Turks who came to Alanya in the 1960s for the alleged healing properties of Damlataş Cave, and later the access provided by Antalya Airport in 1998 allowed the town to grow into an international resort. Strong population growth through the 1990s was a result of immigration to the city, and has driven a rapid modernization of the infrastructure.