Melilla was a Phoenician and later Punic establishment under the name of Rusadir. Later it became a part of the Roman province of Mauretania Tingitana. As centuries passed, it went through Vandal, Byzantine and Hispano-Visigothic hands. Melilla was on the frontier of the Kingdom of Tlemcen and the Kingdom of Fes when Juan Alfonso Pérez de Guzmán (also known as Guzmán El Bueno), the 3rd Duke of Medina Sidonia reconquered it in 1497, a few years after Castile had taken control of the Nasrid kingdom of Granada, the last remain of Al-Andalus.
The limits of the Spanish territory round the fortress were fixed by treaties with Morocco in 1859, 1860, 1861 and 1894. In the late 19th century, as Spanish influence expanded, Melilla became the only authorized centre of trade on the Rif coast between Tetuan and the Algerian frontier. The value of trade increased, goat skins, eggs and beeswax being the principal exports, and cotton goods, tea, sugar and candles being the chief imports.
The Spaniards had had much trouble with the neighboring tribes-the turbulent Rif, independent Berbers (Amazighs) hardly subject to the sultan of Morocco. In 1893 the Rif Berbers besieged Melilla, and 25,000 men had to be dispatched against them. In 1908 two companies, under the protection of El Roghi, a chieftain then ruling the Rif region, started mining lead and iron some 20 kilometers from Melilla. A railway to the mines was begun. In October of that year the Rif revolted from the Roghi and raided the mines, which remained closed until June 1909. On the July 10 the workmen were again attacked and several of them killed. Severe fighting between the Spaniards and the tribesmen followed. The Rif having submitted, the Spaniards, in 1910, restarted the mines and undertook harbour works at Mar Chica. But hostilities broke out again in 1911 and the Rif, inflicting grave defeats on the Spanish (see Disaster of Annual), were not pacified until 1927.
General Francisco Franco used the city as one of his staging grounds for his rebellion in 1936, and a statue of him is still prominently featured.