In April 1931, following Spain’s municipal elections, anti-monarchist candidates won a majority of votes. These elections were considered a referendum on the status of the monarchy and the king, Alfonso XIII. After the elections, the king left Spain and the Second Republic was declared, with Niceto Alcalá-Zamora serving as its first president.

The political and social upheaval that began with the Spanish-American War, and problems from the Rif War and the Catalan nationalism movement, lead to a dictatorship controlled by Miguel Primo de Rivera in 1923. Primo de Rivera was appointed Prime Minister by the King following his seizing of power. Primo de Rivera was forced to resign in 1930, following the loss of support by the army. The king was perceived to have supported the dictator and lead to the anti-monarchist election victories.

The Second Republic would not last. The Spanish Civil War was started in 1936 with a coup lead by the Nationalists to overthrow the Republic. The Nationalists, a right-winged, counter-revolutionary faction, eventually overthrew the Second Republic by 1939. The leader of the Nationalists, General Francisco Franco, would rule Spain until his death in 1975.

Juan Carlos I, grandson of Alfonso XIII, became king following the death of General Franco in 1975.

More Info: en.wikipedia.org