Kingdom of Spain ( Napoleonic ) Napoleonic Spain was the part of Spain loyal to Joseph Bonaparte during the Peninsular War ( 1808 – 1813 ) after the country was partially occupied by French forces . During this period , the country was considered a client state of the First French Empire . That part of Spain which continued to resist French occupation remained loyal to Ferdinand VII and allied with Britain and Portugal to expel Napoleon ' s armies from Spain . Allied victories at Salamanca and Vitoria meant the defeat of the Josefino régime and the expulsion of Napoleon ' s troops . The Treaty of Valençay recognized Ferdinand VII as the legitimate king of Spain . Background : From alliance with France to the Peninsular War . The abdication of Charles IV . Spain had been allied with France against the United Kingdom since the Second Treaty of San Ildefonso in 1796 . However , 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 . In 1806 , ready for an invasion in case of a Prussia victory . Napoleon ' s rout of the Prussian army at the Battle of Jena - Auerstaedt caused Spain to back down . However , Spain continued to resent the loss of their fleet at Trafalgar and the fact that they were forced to join the Continental System . Nevertheless , the two allies agreed to partition Portugal , a long - standing British trading partner and ally , and which refused to join the Continental System . Napoleon was fully aware of the disastrous state of Spain ' s economy and administration , and its political fragility , and came to believe that it had little value as an ally . He insisted on positioning French troops in Spain to prepare for a French invasion of Portugal , but once this was done , he continued to move additional French troops into Spain without any sign of an advance into Portugal . The presence of French troops on Spanish soil was extremely unpopular in Spain , resulting in the Mutiny of Aranjuez and the abdication of Charles IV of Spain in March , 1808 . The installation of Joseph Bonaparte . Charles IV hoped that Napoleon , who by this time had 100 , 000 troops stationed in Spain , would help him regain the throne . However , Napoleon refused to help Charles , and also refused to recognize his son , Ferdinand VII , as the new king . Instead , he succeeded in pressuring both Charles and Ferdinand to cede the crown to his brother , Joseph Bonaparte . The head of the French forces in Spain , Marshal Joachim Murat , meanwhile pressed for the former Prime Minister of Spain , Manuel de Godoy , whose role in inviting the French forces into Spain had led to the mutiny of Aranjuez , to be set free . The failure of the remaining Spanish government to stand up to Murat caused popular anger . On 2 May 1808 , Murat ordered 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 . The Council of Castile , the main organ of central government in Spain under Charles IV , was now in Napoleon ' s control . 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 Parliament 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 . Provincial juntas began to coordinate their actions ; regional juntas were formed to oversee the provincial ones . Finally , on 25 September 1808 , a single Supreme Junta was established in Aranjuez to serve as the acting resistance government for all of Spain . The French occupation . Murat established a plan of conquest , sending two large armies to attack pockets of pro - Ferdinand resistance . One army secured the route between Madrid and Vitoria and besieged Zaragoza , Girona , and Valencia . The other , sent south to Andalusia , sacked Córdoba . Instead of proceeding to Cádiz as planned , General Dupont was ordered to march back to Madrid , but was defeated by General Castaños at Bailén on 22 July 1808 . This victory encouraged the resistance against the French in several countries elsewhere in Europe . After the battle , King Joseph left Madrid to take refuge in Vitoria . In the fall of 1808 , Napoleon himself entered Spain , entering Madrid on 2 December and returning Joseph I to the capital . Meanwhile , a British army entered Spain from Portugal but was forced to retreat to Galicia . In early 1810 , the Napoleonic offensive reached the vicinity of Lisbon , but were unable to penetrate the fortified Lines of Torres Vedras . The two Spains . Reign of Joseph I . The Josephine State had its legal basis in the Bayonne Statute . When Fernando VII left Bayonne , in May 1808 , he asked that all institutions co - operate with the French authorities . Accordingly , the Council of Castile assembled in Bayonne , though only 65 of the total 150 members attended . The Assembly ratified the transfer of the Crown to Joseph Bonaparte and adopted with little change a constitutional text drafted by Napoleon . Most of those assembled did not perceive any contradiction between patriotism and collaboration with the new king . Moreover , it was not the first time a foreign dynasty had assumed the Spanish Crown : at the start of the eighteenth century , the House of Bourbon came to Spain from France after the last member of the House of Habsburg , Charles II , died without offspring . Joseph Bonaparte promulgated the Statute of Bayonne on July 7 , 1808 . As a constitutional text , it is a royal charter , because it was not the result of a sovereign act of the nation assembled in Parliament , but a royal edict . 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 . It recognized the Catholic religion as the official religion and forbade the exercise of other religions . It did not contain an explicit statement about the separation of powers , but asserted the independence of the judiciary . Executive power lay in the King and his ministers . The courts , in the manner of the old regime , were constituted of the estates of the clergy , the nobility and the people . Except with regard to the budget , its ability to make laws was influenced by the power of the monarch . In fact , King was only forced to call Parliament every three years . It contained no explicit references to legal equality of citizens , although it was implicit in the equality in taxation , the abolition of privileges and equal rights between Spanish and American citizens . The Constitution also recognized the freedom of industry and trade , the abolition of trade privileges and the elimination of internal customs . The Constitution established the Cortes Generales , an advisory body composed of the Senate which was formed by the male members of the royal family and 24 members appointed by the king from the nobles and the clergy , and a legislative assembly , with representatives from the estates of the nobility and the clergy . The Constitution established an authoritarian regime that included some enlightened projects , such as the abolition of torture , but preserving the Inquisition . During his stay in Vitoria , Joseph Bonaparte had taken important steps to organise the state institutions , including creating an advisory Council of State . The king appointed a government , whose leaders formed an enlightened group which adopted a reform program . The Inquisition was abolished , as was the Council of Castile which was accused of anti - French policy . He decreed the end of feudal rights , the reduction of religious communities and the abolition of internal customs charges . This period saw measures to liberalize trade and agriculture and the creation of a stock exchange in Madrid . The State Council undertook the division of land into 38 provinces . As the popular revolt against Joseph Bonaparte spread , many who had initially co - operated with Bonaparte dynasty left their ranks . But there remained numerous Spanish , known as " afrancesados " , who nurtured his administration and whose very existence gives the Spanish war of independence civil war character . The afrancesados saw themselves as heirs of enlightened absolutism and saw the arrival of Bonaparte as an opportunity to modernize the country . 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 . 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 Bonaparte tried to exercise full authority as the King of Spain , preserving some autonomy against the designs of his brother Napoleon . In this regard , many afrancesados believed that the only way to maintain national independence was to collaborate with the new dynasty , as the greater the resistance to the French , the greater would be the subordination of Spain to the French imperial army and its war requirements . 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 . The military defeats suffered by the French army forced Joseph I to leave Madrid on two occasions . The king finally left Spain in June 1813 , ending the failed stage of enlightened absolutism . Most of Joseph ' s supporters ( about 10 , 000 and 12 , 000 ) fled to France into exile , along with the retreating French troops after the war . Their property was confiscated . Cádiz Cortes . In 1810 , the Cortes Generales had to move from Seville to Cadiz to escape the French advance . Its members disbanded and transferred its powers to a Council of Regency . The five regents convened the meeting of the Cortes in Cadiz . Cortes were representatives of the estates , but were unable to hold elections either in Spain or in the American colonies . The assembly thus lost its estates in favor of territorial representation . The Constitution of Cádiz . The Cortes opened their sessions in September 1810 on the Isle of Leon . They consisted of 97 deputies , 47 of whom were alternates from Cadiz residents , who approved a decree expressing represent the Spanish nation and declared legally constituted in general and special courts in which lay the national sovereignty . The Allied victory . In March 1813 , threatened by the Anglo - Spanish army , king Joseph left the capital and the Allied offensive intensified and culminated in the Battle of Vitoria , which marked the beginning of the end of French occupation and , in December 1813 , in the Treaty of Valençay , which provided for the restoration of Ferdinand VII .