The Peninsular War (1807–1814) was a military conflict between Napoleon's empire (as well as the allied powers of the Spanish Empire), the United Kingdom of Great Britain and Ireland and the Kingdom of Portugal, for control of the Iberian Peninsula during the Napoleonic Wars. The war began when the French and Spanish armies invaded and occupied Portugal in 1807, and escalated in 1808 when France turned on Spain, previously its ally. The war on the peninsula lasted until the Sixth Coalition defeated Napoleon in 1814, and is regarded as one of the first wars of national liberation, significant for the emergence of large-scale guerrilla warfare.
The Peninsular War overlaps with what the Spanish-speaking world calls the Guerra de la Independencia Española (Spanish War of Independence), which began with the Dos de Mayo Uprising on 2 May 1808 and ended on 17 April 1814. The French occupation destroyed the Spanish administration, which fragmented into quarrelling provincial juntas.
A reconstituted national government, the Cádiz Cortes—in effect a government-in-exile—fortified itself in Cádiz in 1810, but could not raise effective armies because it was besieged by 70,000 French troops. British and Portuguese forces eventually secured Portugal, using it as a safe position from which to launch campaigns against the French army and provide whatever supplies they could get to the Spanish, while the Spanish armies and guerrillas tied down vast numbers of Napoleon's troops. These combined regular and irregular allied forces, by restricting French control of territory, prevented Napoleon's marshals from subduing the rebellious Spanish provinces, and the war continued through years of stalemate.
The British Army, under then Lt. Gen. Sir Arthur Wellesley, later created the Duke of Wellington, guarded Portugal and campaigned against the French in Spain alongside the reformed Portuguese army. The demoralised Portuguese army was reorganised and refitted under the command of Gen. William Carr Beresford, who had been appointed commander-in-chief of the Portuguese forces by the exiled Portuguese royal family, and fought as part of a combined Anglo-Portuguese army under Wellesley.
In 1812, when Napoleon set out with a massive army on what proved to be a disastrous campaign to conquer Russia, a combined allied army under Wellesley pushed into Spain, defeating the French at Salamanca and taking Madrid. In the following year Wellington scored a decisive victory over King Joseph's army at Vitoria. Pursued by the armies of Britain, Spain and Portugal, Marshal Jean-de-Dieu Soult, no longer able to get sufficient support from a depleted France, led the exhausted and demoralized French forces in a fighting withdrawal across the Pyrenees during the winter of 1813–1814.