Meanwhile the attack on the west face of the town had succeeded, after one or two attempts, and soldiers of the fifth division were making their way into the empty streets. Wellington, ignorant of this, and perceiving no movement from the castle, the capture of which had been reported to him, ordered the assailants of the breaches to withdraw and re-form for a fresh attack. This however was not necessary: the French, taken in flank both from the castle and from the west, abandoned the defence. The relics of the garrison which had withdrawn to the outlying fort north of the Guadiana surrendered next morning. Over the frightful expenditure of life in this storm, and over the horrors of the sack of Badajos, it is better to draw a veil. Wellington's Peninsular veterans were capable of any deeds of desperate courage, or of steady endurance, but they were also capable of great atrocities on the rare occasions when their officers lost control over them.

The Spaniards, to whom Ciudad Rodrigo had been handed over, had so grossly neglected the duty of repairing the fortifications, and the Portuguese government was so dilatory, to use no stronger word, in supplying all four fortresses, that Wellington's plan for invading Andalusia, to fight Soult there, was necessarily abandoned. The defensive side of his duty was obviously the essential one. Still he had it now in his power to choose his own route and his own time for entrance into Spain: and he utilised the interval to render the communications of the French circuitous and difficult. Soult's bridge train having been captured in Badajos, a stroke of good fortune which matched the capture of Marmont's siege train in Ciudad Rodrigo, they could only cross the Tagus at permanent bridges. The lowest bridge on the Tagus, a boat bridge protected by three small forts, was at Almaraz; and General Hill by a brilliant dash seized the forts and destroyed the bridge. Almost simultaneously the bridge over the Tagus at Alcantara, down in Portugal, was skilfully repaired. The combined result of the two operations was to make the communication between Hill, who was left to watch the Guadiana, and Wellington when he moved to the Douro region, a fortnight shorter than the distance between Marmont and Soult's northernmost division.

On June 13, the spring rains being over, Wellington, having concentrated his immediate army near Ciudad Rodrigo, marched on Salamanca. His motives for deciding to operate against Marmont rather than in Andalusia seem to have been various, some embracing the whole area of the Peninsula, one at least the practical consideration that his supplies, brought by water up the Douro, could more quickly and easily be conveyed to the army. He had no intention of running serious risks, or of fighting a great battle unless he could do so under favourable conditions. If successful, he could greatly shake the French hold on Spain: if he found Marmont too strong, his retreat into Portugal was insured by possession of the fortresses. Marmont retired at once, leaving garrisons in the forts round Salamanca. These forts offered unexpectedly long resistance, and Wellington, encamped on the high ground north-east of the city, did not think it prudent to risk a battle until they were in his hands, though Marmont's somewhat rash manœuvres, undertaken in the hope of saving them, gave him more than one opportunity. On the 27th the forts fell, and Marmont, having no longer any motive for lingering near Salamanca, and expecting reinforcements from the north, promptly retreated behind the Douro. Wellington followed, but could not pass the river, of which the enemy held or had destroyed the bridges, except by deep and dangerous fords. He could only wait for his antagonist to make the next move, which soon came. On receiving his reinforcements, Marmont re-crossed the Douro, and a series of complicated movements ensued, in which Marmont out-manœuvred Wellington, compelling him to retire on Salamanca again, and seizing passages over the river Tormes above the city. That river, after flowing northwards for some distance, makes a great bend to the westward from a point about east of Salamanca, and then after passing the town, which is on its right bank, flows away north-westwards into the Douro. It was in the space enclosed by this curve of the Tormes, south-east from Salamanca, that the great battle was fought. Marmont's purpose in crossing the river into this space was to threaten the Ciudad Rodrigo road, and so compel Wellington to retreat or lose his one line of communication. Wellington naturally also crossed the Tormes by the fords near Salamanca: being aware that further reinforcements, especially of cavalry, in which Marmont was relatively deficient, would arrive in a day or so, he had made up his mind to retreat at night unless something unexpected should happen. And the unexpected did happen: Marmont, who had hitherto carried off the honours of the campaign so far as manœuvring went, for there had been no important fighting, suddenly committed a gross tactical blunder.

Early on the morning of July 22, Wellington's army occupied a position three or four miles from Salamanca, the left resting on the ford of Santa Marta above the town, with Pakenham's division beyond the river, and the right extending nearly to two small rugged hills, called the Arapiles. Marmont, whose object was to turn the English right, and so cut them off from the Ciudad Rodrigo road, and compel them to fight with their backs to the Tormes, made a demonstration towards Wellington's right front, driving in the cavalry occupying posts in front, while the mass of the French army marched in a direction to bring them across the flank of the English line. The possession of the Arapiles would have enabled him to form line across Wellington's flank unopposed, if not undiscovered: accordingly he sent forward a detachment to seize them. A staff officer saw this movement beginning, and informed Wellington, who hitherto had neglected the little hills, apparently not expecting Marmont's movement. Just in time a Portuguese regiment occupied the northernmost of the two Arapiles, but the French could not be prevented from seizing the other. Marmont had thus secured part of the advantage he aimed at, on the other hand Wellington was now fully aware of his adversary's purpose. Accordingly he formed his army on a new front facing southwards: what had been his right became the left resting on the Arapiles hill, the main body massed on the slopes behind the hill, while the right occupied the little village of Arapiles. Pakenham's division, with its attendant brigade of cavalry, was at the same time brought across the Tormes, and posted at Aldea Tejada, two or three miles off, where it covered the Ciudad Rodrigo road, and was completely out of sight of the French. Wellington had thus gone far towards neutralising the advantage which he had allowed Marmont to gain in turning his right: he held a strong position, difficult to assail, and it was open to him to retreat under cover of the darkness, though it would have been more than dangerous to do so in the day-time.

Several hours passed away, for a great part of Marmont's army had far to march before coming into position. The marshal at last grew impatient, and in order to draw Wellington from his position, ordered his left, Thomière's division of infantry with a quantity of cavalry and guns, to move westwards so as to threaten the Ciudad Rodrigo road. Marmont was of course totally ignorant that Pakenham's division was ready to stop any such movement: but anyhow the mistake was flagrant, as gross as the blunder of the allies at Austerlitz. Wellington instantly poured his troops down from behind the Arapiles hill on to the lower ground about the village of the same name, and formed in two lines, the right flanked by cavalry. At the same time he ordered Pakenham to advance against the line of march of the French left. Marmont saw too late that he had been over hasty: the divisions which were to form his centre were not yet on the ground. Wellington's advance had brought him under a heavy fire from the enemy's artillery ranged opposite him, and Marmont hoped that this might serve to check the English until he could retrieve his mistake. It was too late: suddenly he saw Pakenham's troops come into view and meet Thomière's long column of march, while two English batteries took it in flank. Marmont personally was spared further effort, for a shell struck him down with a broken arm and other wounds as he descended from the Arapiles. The fall of the commander increased the confusion, the more so as the next in command was soon also wounded. The rout of Thomière's division was soon complete, and its commander was killed. Wellington had only waited for Pakenham to come well into action before advancing in the centre, at the same time sending a brigade to assail the Arapiles hill held by the French. The battle raged fiercely for a short time along the front, where Clausel, on whom the command had devolved, had now come up into line. The French left was to all intents and purposes destroyed, partly by Pakenham, partly by a grand charge of Le Marchant's cavalry, which dashed forward from the right of the main body. The centre and right kept up the conflict for some time longer, all the better because the English attack on the Arapiles had been heavily repulsed. The battle however was lost, and Clausel had only to retreat as best he could. This he managed with great skill, covering his rear with clouds of skirmishers, until gradually his troops gained the shelter of the forest from which they had emerged in the forenoon with every prospect of victory. The oncoming darkness prevented direct pursuit, but Wellington was little concerned at this, for he had pushed forward on his left the divisions that had formed his reserve towards the fords by which alone the French could cross the Tormes, assuming that the castle of Alba de Tormes was held by the Spanish troops which he had placed there. The Spanish commander had however evacuated the place on Marmont's approach the previous day, and had carefully omitted to inform Wellington. Hence the French were able to escape by Alba with much less loss in prisoners than well might have been. The French loss however was very serious: out of about 42,000 men nearly 12,000 were killed, wounded, or taken prisoners. Wellington had to pay the heavy price of 6000 men out of 46,000 for his victory; but by it he shook the French hold on Spain in every corner of the country.

Though the defeated army was seriously disorganised beyond its heavy losses, Clausel nevertheless tried to make a stand beyond the Douro, in the expectation that king Joseph, with the small army at his immediate disposal, would there join him. Joseph was distracted between many counsels, and consequently did not act promptly. Wellington however decided the question for him. Forcing Clausel from the Douro, he entered Valladolid, seizing the French stores there. Then leaving a small force to face Clausel, who had retreated towards Burgos, and who could not be in a condition to resume offensive operations for some time, Wellington turned upon Joseph, and easily drove him from Madrid. The intruding king, after much hesitation, retired eastwards, and sent positive orders to Soult to evacuate Andalusia and bring his army to the east side of Spain. The occupation of Madrid by Wellington involved the capture of a vast quantity of French material of war, which they found it difficult to replace; but the moral effects were incomparably greater, as an encouragement to the Spanish people. A great part of the north was already in a state of insurrection, in spite of the presence of French troops: this stroke stimulated them by the hope of speedy success, besides setting the whole south free from the invaders. Wellington was perfectly aware that his hold on Madrid could be but temporary: as soon as Soult and Joseph were united, they would have strength enough to compel him to retire. This could not however take place immediately: so Wellington, leaving Hill at Madrid, marched northwards, hoping to inflict another blow on Clausel's army, now commanded by Souham, in the time at his disposal. At Burgos he allowed himself to be drawn into a siege of the castle, which was bravely and skilfully defended, and proved impregnable to field artillery, which was all that Wellington had with him. The concentration of the enemy's armies in the east rendered it impossible for him to maintain his position much longer. Accordingly on October 21 he began for the last time a retreat into Portugal, Hill also abandoning Madrid. The latter part of the retreat had to be conducted in frightful weather, and was marked by more disorder in the British army than occurred at any other time during the war; thus the losses were severe, out of all proportion to the pressure which the French were able to exercise.

Just at the time when Wellington turned his back on Burgos, Napoleon's retreat from Moscow began. Before the end of the year he was driven out of Russia, having lost nearly half-a-million of men: Prussia also, hitherto his nominal ally, rose in arms against him. In order to make head against Russia and Prussia on the Elbe, he had to withdraw troops from Spain, besides directing to Germany reinforcements and supplies which otherwise might have been devoted to the Spanish armies. Hence when the campaign of 1813 began, Wellington had the superiority of strength, though his enemies were now less widely scattered than before the evacuation of Andalusia. There could be no doubt that to invade Spain once more in the same general direction as in 1812 would be the most effective. Even Sir John Moore's small force, boldly plunging into Spain by that route at the end of 1808, had made Napoleon fear for his line of communication with France, and compelled him to detach overwhelming forces against the English. A fortiori Wellington, advancing by that line with an army equal to all that king Joseph could bring together, must compel him to evacuate Madrid, and retreat sufficiently far northwards to guard the main road to France. Wellington knew by his experience of the last year that the line of the Douro beyond Salamanca was difficult to force in the face of a fairly equal enemy. He therefore resolved that a large portion of his army should cross the Douro down in Portugal, and then move eastwards, while he himself advanced viâ Salamanca. The pressure of his left wing would compel the French in his front to retire, for fear of being completely outflanked. And here came in the advantage which he derived from the English command of the sea. Instead of dragging behind him an ever-lengthening chain, in the shape of communication with Lisbon, which had hitherto been his base for supplies, he could, if confident of having the upper hand in the north-west of Spain, have his supplies brought to the northern ports, and conveyed thence by comparatively short journeys. And he was confident, so thoroughly so as to let it be seen; it is told that when he passed the frontier into Spain, he rose in his stirrups, and looking round waved his hand, exclaiming: "Farewell, Portugal!" During four weary years he had stood substantially on the defensive, guarding the frontier if he could, retreating if he could not, obliged to withdraw behind it after incursions into Spain. Now at last his turn was come, and he knew it.