Nerja's foundation date is unknown, but it seems that it existed as a town in the times of Aberramán III. The first written information about Nerja is by the Arabic poet Ibn Sadí, a traveller who passed through in the year 917 and who referred to it as a hamlet, but nearly as big as a town, surrounded by leafy markets, and admired by all that lived there or passed through. The Arabs gave it the name, Naricha or Narija (abundant spring). It was formed in part during Muslim reign of Rayya and the local population settled under the protection of the ruler's castle, whose remains can still be seen today in the angle that forms the road to Frigiliana and the crossroad with the local quarry. Before this date there is no reference of settlements in the area that Nerja occupies, nevertheless, certain theories assume a form of human habitat during the Upper Palaeolithic age, which dates back to between 10,000 to 40,000 years ago, and evidence was found to support this in the now famous Nerja Caves. There is also evidence near to the centre of Nerja, where a Roman settlement existed, a hypothesis derived from the closeness of the Roman town of Detunda (Maro).
In June 1500, after the Duke of Nájera conquered Vélez, Nerja was by this time already Christian. The Muslim population there however were granted permission to remain with all their properties. After the Mudéjar uprising, and consequential leaving of the area, Doña Juana granted resettlement for the old Christians, who then occupied the abandoned dwellings, and she decreed that they should be free of paying taxes and of all other services, petty theft or impositions, privileges that were confirmed by Philip III and Philip IV.
At the end of the 18th Century, Nerja had a town council formed with two mayors, three M.P.s and an elected representative starting the municipal independence at the start of the 19th Century.
In 1509, the castle on the cliffs was rebuilt and only then did Nerja as we know it, begin to take shape. The local population, by then made up of relocated Spaniards from the north of Spain, began to build houses and other buildings around the fortress and along the coast. A full defensive system comprising castles and watchtowers spanned the coastline at this time and protected the coast by lighting fires which in turn warned the next watchtower along of the impending danger. These towers remained, guarding Nerja until both castles were destroyed by the English in 1812 to prevent them from falling into the hands of the invading Napoleonic army. Later that century, Nerja was to witness two local disasters; one, the phylloxera plague that destroyed the vines and the second, a powerful earthquake that affected much of Málaga and Granada provinces. It wasn't until the arrival of the tourist boom in early 1960's that Nerja once again started to prosper.