Battle of Ilerda

The Battle of Ilerda took place in June 49 BC between the forces of Julius Caesar and the Spanish army of Pompey Magnus, led by his legates Lucius Afranius and Marcus Petreius. Unlike many of the other battles of the civil war, this was more a campaign of manoeuvre than actual fighting. It allowed Caesar to eliminate the threat of Pompey’s forces in Spain and face Pompey himself in Greece at the Battle of Pharsalus (48 BC).
Background.
After having driven the Optimates from Italy, in March 49 BC Caesar turned his attention to the Republican army in the Spanish provinces. On his way to Spain, Caesar was delayed when the port city of Massilia rebelled under the leadership of Lucius Domitius Ahenobarbus in April. Leaving the siege of Massilia to Gaius Trebonius and Decimus Junius Brutus Albinus, Caesar moved to Hispania Citerior to reinforce the three legions he had sent there as an advance guard under his legate Fabius.
Ilerda Campaign.
Fabius had taken control of several passes through the Pyrenees and after being reinforced by another three legions had moved into the Peninsula. The Pompeians, commanded by Afranius and Petreius, encamped on a hill south of the city of Ilerda on the western side of the river Sicoris. In this way Afranius and Petreius had access to the land for foraging to the east of the river through the stone bridge by the city, and water. Fabius and his army were east of the Sicoris and decided to constructed two new wooden bridges across the river upstream from Ilerda. After finishing his bridges Fabius marched his army across and also encamped on the western bank. Since the Pompeians had striped the western bank of supplies Fabius had to send foraging parties across the river to supply his army. During these foraging missions the Caesarians fought many skirmishes with the Pompeian cavalry. On one of these missions, just after two of his legions had crossed the river, the bridge they were using was swept away. The wreckage of the bridge floated by Ilerda, and Afranius decided to lead four of his legions and his cavalry across the stone bridge to attack Fabius's isolated two legions. Lucius Plancus, the commander of the two legions, took up a position on a nearby hill, where he was soon attacked. He was only saved by the arrival of Fabius's other two legions, which had crossed the other bridge. 
Two days later Caesar arrived at Fabius's camp and took command. Caesar endeavored to camp about 400 paces from the foot of the hill where the Pompeians were encamped. While the Pompeians under Afranius threatened to give battle, Caesar declined, but had his first two lines of troops form up for battle anyway, while the third line was ordered to dig a wide ditch behind the lines, unseen. As night came, Caesar withdrew his army behind the ditch and spent the night under arms.
The next day was spent creating the rest of the ditch and the rampart which would form the defences of Caesar's camp. For this operation Caesar kept a part of his force on guard. The Pompeian forces were half a mile outside Ilerda, which held much of their supplies, with a small hill between. Caesar decided to try and seize this hill, fortify it and cut the Pompeian position in half. In the midst of the plain there was a portion of rising ground which Caesar wanted to occupy. As he tells it:
Between the city of Ilerda, and the hill where Petreius and Afranius were encamped was a plain of about three hundred paces, in the midst of which was a rising ground, which Caesar wanted to take possession of; because, by that means, he could cut off the enemy's communication with the town and bridge, and render the magazines they had in the town useless.
The contest for this hill led to a protracted battle.
Battle.
Both armies sent detachments towards the hill and the Pompeians occupied it first. This, combined with their skirmish-like combat technique, overwhelmed the Caesarian detachment and his troops were forced to give ground, eventually retreating to safety. 
This minor reverse would result in Caesar spurning a renewed attack and this, in turn, led to a longer engagement. As Caesar tells it (in the third person, as was his style):
Caesar, contrary to his expectation, finding the consternation like to spread through the whole army, encouraged his men, and led the ninth legion to their assistance. He soon put a stop to the vigorous and insulting pursuit of the enemy, obliged them to turn their backs, and pushed them to the very walls of Ilerda. But the soldiers of the ninth legion, elated with success, and eager to repair the loss we had sustained, followed the runaways with so much heat that they were drawn into a place of disadvantage, and found themselves directly under the hill where the town stood, whence when they endeavoured to retire, the enemy again facing about, charged vigorously from the higher ground. The hill was rough, and steep on each side, extending only so far in breadth as was sufficient for drawing up three cohorts; but they could neither be reinforced in flank, nor sustained by the cavalry. The descent from the town was indeed something easier for about four hundred paces, which furnished our men with the means of extricating themselves from the danger into which their rashness had brought them. Here they bravely maintained the fight, though with great disadvantage to themselves, as well on account of the narrowness of the place, as because being posted at the foot of the hill, none of the enemy's darts fell in vain. Still however they supported themselves by their courage and patience, and were not disheartened by the many wounds they received. The enemy's forces increased every moment, fresh cohorts being sent from the camp through the town, who succeeded in the place of those that were fatigued. Caesar was likewise obliged to detach small parties to maintain the battle, and bring off such as were wounded. The fight had now lasted five hours without intermission, when our men, oppressed by the multitude of the enemy, and having spent all their darts, attacked the mountain sword in hand, and overthrowing such as opposed them, obliged the rest to betake themselves to flight. The pursuit was continued to the very walls of Ilerda, and some out of fear took shelter in the town, which gave our men an opportunity of making good their retreat. At the same time the cavalry, though posted disadvantageously in a bottom, found means by their valour to gain the summit of the mountain, and riding between both armies, hindered the enemy from harassing our rear. Thus the engagement was attended with various turns of fortune. Caesar lost about seventy men in the first encounter, among whom was Q. Fulginius, first centurion of the Hastati of the fourteenth legion, who had raised himself by his valour to that rank, through all the inferior orders. Upwards of six hundred were wounded. On Afranius's side was slain T. Caecilius, first centurion of a legion; also four centurions of inferior degree, and above two hundred private men.
Aftermath.
The spring storms and the melting snow from the mountains then caused flooding, which particularly affected the lower-situated Caesarians, whose camp was flooded. This meant that the Caesarian troops were unable to forage and famine struck the army, accompanied by disease. When the flood of the river Sicoris finally withdrew, the Caesarians dug deep culverts with which to divert the river. This caused Petreius and Afranius to abandon their camp and the city of Ilerda and retreat towards a second republican army under Marcus Terentius Varro. Caesar sent his cavalry across and after the infantry indicated its assent, had his legions go across in the shoulder height water.
Caesar ordered a pursuit which overtook the retreating rear guard of the republican army and with a feint retreat he was able outmaneuver them and to block the route on which the republicans were retreating. The two armies again camped close to each other leading to some fraternization between the two armies. Petreius, wanting to stop this fraternization, had the Caesarian soldiers who had wandered into the republican camp rounded up and killed. After this the republicans again retreated towards Ilerda, only to become besieged by the Caesarians in their new camp. By 30 July, Caesar had completely surrounded Afranius and Petreius's army. Afranius and Petreius's ask for terms of surrender to Caesar, and in front of both armies, Caesar accepted the surrender of the five Pompeian legions.
After the surrender of the republican main army in Spain, Caesar then marched towards Varro in Hispania Ulterior, who at once without a fight submitted to him leading to another two legions surrendering. After this, Caesar left his legate Quintus Cassius Longinus —the brother of Gaius Cassius Longinus— in command of Spain with four of the legions, partly made up of men who had surrendered and gone over to the Caesarian camp, and returned with the rest of his army to Massilia and its siege.