Spain had suffered a military defeat in the Rif War in Morocco. In September 1923 with the support of the Spanish King Alfonso XIII the military staged a coupe and installed General Miguel Primo de Rivero as head of state. He ruled as a dictator ignoring the 1876 Constitution. During the period of his rule Spain was able to turn the tide and end the war in Morocco. The period was a prosperous one for Spain. However by 1929 the world wide depression was impacting Spain and the government became very unpopular. This forced the King to remove de Rivero who was replaced first by Damaso Berenguer and then by Admiral Aznar-Cabanas.
In April 1931 municipal elections were held throughout Spain the Republican Parties won and overwhelming victory. This was seen as a referendum on the monarchy and the King fled the country.
A provisional government was installed with Niceto Alcala Zalamo presiding on April 14, 1931. An election was held in June 1931 where women were given the right to vote for the first time. A new constitution was drafted and approved by the new parliament which was led by a coalition of liberals and socialists, with Manuel Azana as the premier. With the approval of the new constitution on December 9, 1931, the Second Republic of Spain was declared.