Spanish confidence was badly shaken after the war against the United States of America which saw the empire lose her remaining colonies outside her immediate vicinity. Separatist movements in the Basque country and Catalonia gained support, the Church interfered in politics, and a radical workers movement destabilized the balance between conservatives and liberals. After taking the government in 1902, King Alfonso XIII showed expansionist tendencies, as demonstrated by the intervention in Morocco. The Algeciras Act of 1906 acknowledged Spanish interests in Morocco, and a protectorate over the North and South of the country was established in 1912, but it became a source of permanent unrest.
While Spain remained essentially neutral throughout the Weltkrieg, 1918 saw social tensions erupt in a number of revolts by the rural populace, right wing factions and the increasingly powerful anarcho-syndicalist movement. Spain allowed the Germany navy to use Spanish ports as based starting from 1919 until the end of the war. Alfonso XIII supported the military coup against the government by General Miguel Primo de Rivera who abolished the constitution of 1876 and installed a dictatorial rule between 1923 and 1930. He ended the uprising in Morocco with a victory over Abd el-Krim in 1926, but could not master the economic crisis and had to resign after repeated revolts by the military and students. His position was taken over by José María Gil-Robles y Quiñones, a moderate right-wing politician.
Deep divisions remain within Spanish society in 1936; on one hand, the resurgent Carlist Movement, headed by Alfonso Carlos and Xavier de Borbón-Parma, aims to re-establish the "True Dynasty" and recreate an integralist Christian monarchy and on the other, the anarcho-syndicalist CNT-FAI has been inspired by the uprisings in both France and Britain to seek the abolition of the Spanish state altogether, and replace it with a voluntarist federation of communes and economic collectives.