The Napoleonic government was opposed by various regions remaining loyal to Ferdinand VII of the old Bourbon kingdom, which formed a series of Juntas allied with the Coalition forces of Britain and Portugal.
Fighting across the Iberian Peninsula would be largely inconclusive until a series of Coalition victories from 1812 to 1813 at Salamanca and Vitoria meant the defeat of the Bonapartist régime and the expulsion of Napoleon I's troops.
After the defeat of the combined Spanish and French fleets by the British at the Battle of Trafalgar in 1805, cracks began to appear in the alliance, with Spain preparing to invade France from the south after the outbreak of the War of the Fourth Coalition.
The presence of French troops on Spanish soil was extremely unpopular in Spain, resulting in the Tumult of Aranjuez by supporters of Ferdinand VII, the heir apparent to the throne.
On 2 May 1808, the younger son of Charles IV, the Infante Francisco de Paula, left Spain for France, leading to a widespread rebellion in the streets of Madrid.
However, due to the popular anger at French rule, it quickly lost authority outside the population centers which were directly French-occupied.
To oppose this occupation, former regional governing institutions, such as the Cortes of Aragon and the Board of the Principality of Asturias, resurfaced in parts of Spain; elsewhere, juntas (councils) were created to fill the power vacuum and lead the struggle against French imperial forces.
Finally, on 25 September 1808, a single Supreme Central Junta was established in Aranjuez to serve as the acting resistance government for all of Spain.
Having successfully appointed Joseph I King of Naples in 1806 and other family rulers in Holland in 1806 and Westphalia in 1807, it came as a surprise to have created a political and later military disaster.
The text was imbued with a spirit of reform, in line with the Bonaparte ideals, but adapted to the Spanish culture so as to win the support of the elites of the old regime.
Many had been a part of government in the reign of Charles IV, for example, François Cabarrus, former head of finance and Mariano Luis de Urquijo, Secretary of State from November 1808 to April 1811.
[2] But there were also writers like playwright Leandro Fernández de Moratín, scholars like Juan Antonio Llorente, the mathematician Alberto Lista, and musicians such as Fernando Sor.
Throughout the war, Joseph I tried to exercise full authority as the King of Spain, preserving some autonomy against the designs of his brother Napoleon I.
In fact, the opposite was the case: although in the territory controlled by King Joseph I modern rational administration and institutions replaced the Old Regime, the permanent state of war reinforced the power of the French marshals, barely allowing the civil authorities to act.
He lived there from 1817 to 1832,[3] initially in New York City and Philadelphia, where his house became the centre of activity for French expatriates, he married American Ann Savage in Society Hill.
Joseph Bonaparte returned to Europe, where he died in Florence, Tuscany (present day Italy), and was buried in the Les Invalides building complex in Paris, France.
In March 1813, threatened by the Anglo-Spanish army, Joseph I had left the capital and the Coalition offensive intensified and culminated in the Battle of Vitoria in June.
French troops were finally evicted from Spain following the conclusion of the Siege of San Sebastián in September 1813, so removing any possibility of a return.