The Borbonic dinasty (in the person of Alfonso XII) recovered the throne in 1876 the same way it had lost it in 1868: by means of a military
pronunciamiento (at Sagunto by general Martínez Campos). This put the new regime in an awkward situation: they wanted to protect a regime born out of a military coup from further meddling of the army into politics.
They managed it more or less for the following 25 years thanks to a series of reasons:
- The general exhaustion of the country after the agitated and bloody 8 years than had passed between 1868 and 1876, many people wanted internal peace and stability at any price.
- The first action of the new regime was to lead the army (commanded in the field by Martínez Campos) to a quick and definitive victory in the Third Carlist War.
- Then they shipped Martínez Campos, along with the best fighting units in the army, to Cuba, where the aforementioned general was able to fight the rebels to a stalemate (the Paz de Zanjón).
- With these successes, Martínez Campos' prestige in the army skyrocketed, and as he was in good personal terms with the duumvirate that controlled the (corrupt and riddled) political system of the Restoration, formed by Antonio Cánovas del Castillo and Práxedes Mateo Sagasta, stability was guaranteed.
But this was a highly personalist system, based not on institutions, but on strong personalities, subjected to the imperatives of biology. In 1895, war erupted in Cuba again, and the old general Martínez Campos failed to control it. The following year, Cánovas was murdered by an anarchist, in 1898 the disaster of Cuba and the Philippines happened and in 1902 Sagasta died. In this very moment, when crisis had shattered the self-confidence of the army, the political system of the Restoration went into a nosedive due to the death of its leaders. The Liberal and Conservative parties quickly degenerated into "taifa kingdoms" and the system rotted away into 1923, with nobody being able to take the decisive step and reform it into a true democratic, functional constitutional monarchy. Also, by this time anarchist and socialist organizations and parties began to appear and to make themselves heard in political debate, and nationalist parties appeared in Catalonia and the Basque Country. All this alarned greatly the economic and political elite of the Restoration, with whom the upper leadership of the army increasingly identified itself.
To make things worse, king Alfonso XIII came to age in this very timeframe and given the political void he took a liking to meddling into politics, especially into military affairs, clearly violating the boundaries of his powers as established by the 1876 Constitution. Had he been a responsible monarch, perhaps he would've been a benign influence, but he was a model of frivolity and irresponsibility in everything he did in life.
That the army would also step into this political void was almost unavoidable, because nobody was in a position to stop them from doing so. Also, Alfonso XIII's support for Primo de Rivera's pronunciamiento in Barcelona was almost a given from the start, because the
Cortes were about to start discussing the famous
Expediente Picasso, about the personal involvement of the king in the events that led to the disaster of Annual. Primo's coup saved him and kept his royal butt firmly glued to the throne for 8 more years, and right to the end the king tried to keep the army involved. The main reason why he fled after the April 1931 municipal election was that most high officers (especially general Sanjurjo, then commander of the Civil Guard) told him that they were not going to repeat Primo de Rivera's 1923
pronunciamiento to save his ass.