In 1898, Spain lost its last major overseas colonies (Cuba, Guam, Puerto Rico, and the Philippines) in the Spanish–American War.
The rapid collapse was perceived as a disaster in Spain, undermining the credibility of both the government and its associated ideologies and almost leading to a military coup d'état led by Camilo Polavieja.
This was the start of the system's decline, giving energy to all manner of conflicting opposition movements at a local and national level.

The failed attempts to conquer Morocco (Melilla War) caused great discontent at home and ended in a revolt in Barcelona, known as the Semana Tragica, in which the lower classes of Barcelona, backed by the anarchists, communists, and republicans, revolted against what they considered the unjust methods for recruiting soldiers.
The government declared a state of war and sent the army to crush the revolt, causing over a hundred deaths and the execution of Francisco Ferrer.
The socialist Unión General de Trabajadores (UGT) and the anarchist Confederación Nacional del Trabajo (CNT) decided to initiate a general strike across the country, but it failed because the unions could only mobilize urban workers.

The problems in Morocco worsened as an army of natives attacked the Spanish army.
They achieved surprise and, due to the skill of the Moroccan chieftain, Abd-Al-Krim, virtually annihilated the Spanish army, advancing almost as far as Melilla in the Battle of Annual.
This Spanish defeat was due to improper planning and was blamed on the top military officers, causing great discontent among the military, who felt misunderstood, because they had been directed to advance into the interior without adequate resources to occupy the difficult territory.
In 1898, Spain lost its last major overseas colonies (Cuba, Guam, Puerto Rico, and the Philippines) in the Spanish–American War. The rapid collapse was perceived as a disaster in Spain, undermining the credibility of both the government and its associated ideologies and almost leading to a military coup d'état led by Camilo Polavieja. This was the start of the system's decline, giving energy to all manner of conflicting opposition movements at a local and national level.
The failed attempts to conquer Morocco (Melilla War) caused great discontent at home and ended in a revolt in Barcelona, known as the Semana Tragica, in which the lower classes of Barcelona, backed by the anarchists, communists, and republicans, revolted against what they considered the unjust methods for recruiting soldiers. The government declared a state of war and sent the army to crush the revolt, causing over a hundred deaths and the execution of Francisco Ferrer. The socialist Unión General de Trabajadores (UGT) and the anarchist Confederación Nacional del Trabajo (CNT) decided to initiate a general strike across the country, but it failed because the unions could only mobilize urban workers.
The problems in Morocco worsened as an army of natives attacked the Spanish army. They achieved surprise and, due to the skill of the Moroccan chieftain, Abd-Al-Krim, virtually annihilated the Spanish army, advancing almost as far as Melilla in the Battle of Annual. This Spanish defeat was due to improper planning and was blamed on the top military officers, causing great discontent among the military, who felt misunderstood, because they had been directed to advance into the interior without adequate resources to occupy the difficult territory.
Restoration (Spain)