Mining companies began to enter the hinterland of Melilla by 1908. A Spanish one, the Compañía Española de las Minas del Rif, was constituted in July 1908, shared by Clemente Fernández, Enrique Macpherson, the Count of Romanones, the Duke of Tovar and Juan Antonio Güell , who appointed Miguel Villanueva as chairman. Thus two mining companies under the protection of Bou Hmara, started mining lead and iron some 20 kilometers (12.4 miles) from Melilla. They started to construct a railway between the port and the mines. In October of that year the Bou Hmara’s vassals revolted against him and raided the mines, which remained closed until June 1909. By July the workmen were again attacked and several were killed. Severe fighting between the Spaniards and the tribesmen followed, in the Second Melillan campaign that took place in the vicinity of Melilla.
In 1910, the Spaniards restarted the mines and undertook harbor works at Mar Chica, but hostilities broke out again in 1911. On 22 July 1921, the Berbers under the leadership of Abd el Krim inflicted a grave defeat on the Spanish at the Battle of Annual. The Spanish retreated to Melilla, leaving most of the protectorate under the control of the Republic of Rif.
In the context of the passing of the Ley de Extranjería in 1986, and following social mobilization from the Berber community, conditions for citizenship acquisition were relaxed and allowed for the naturalization of a substantial number of inhabitants, until then born in Melilla but without Spanish citizenship.
On 6 November 2007, King Juan Carlos I and Queen Sofia visited the city, which caused a demonstration of support. The visit also sparked protests from the Moroccan government. It was the first time a Spanish monarch had visited Melilla in 80 years.
Melilla (and Ceuta) have declared the Muslim holiday of Eid al-Adha or Feast of the Sacrifice, as an official public holiday from 2010 onward. This is the first time a non-Christian religious festival has been officially celebrated in Spain since the Reconquista.
In 2018, Morocco decided to close the customs office near Melilla, in operation since the mid 19th century, without consulting the counterparty.