Gibraltar was ruled by the Kingdom of Castile between 1309 and 1333, after having been in Muslim hands for almost 600 years. The
Marinid ruler Abu al-Hasan Ali ibn Othman allied with his Granadan counterpart, Muhammed IV, to mount a siege of the fortified town between February–June 1333. The Castilian garrison held out for over four months but starvation forced it to capitulate only a few days before a relief force under the Castilian king, Alfonso XI, was due to arrive. Alfonso already had a fleet in the
Bay of Gibraltar under the command of Admiral Alfonso Jofre de Tenorio. His army's overland march from
Jerez de la Frontera had been held up by squabbles with his nobles, whom he had to persuade to continue on after the news of Gibraltar's fall arrived on 20 June. He pointed out that the Moors would not yet have secured their position in the fortress; they would still be taking stock, repairing the damage that they had caused to the fortifications and reprovisioning the new garrison. There was no time to lose in pressing a counter-attack. The Castilians left their encampment by the
Guadalete river near Jerez and marched first to
Alcalá de los Gazules, taking the direct but mountainous route to Gibraltar. On 26 June they reached
Castellar de la Frontera on the upper reaches of the
Guadarranque river and marched down the river's left bank towards the old Roman city of
Carteia at the head of the Bay of Gibraltar. A 6,000-strong Moorish force from nearby
Algeciras under Abd al-Malik followed them on lower ground near the coast. Alfonso stuck to the high ground of the
Sierra Carbonera from which the Moors sought to lure him into an ambush as his army descended the slope towards Gibraltar. The Castilian king realised the Moors' intentions and set a trap for them in turn. He sent his rear guard directly down the slope while his cavalry, archers and lancers outflanked the Moors by working their way through the woods on the sides of the mountain. Alfonso anticipated that the Moors would seek to gain the crest, from where they would descend to attack the rear guard. His flankers would in turn occupy the newly vacated crest, sandwiching the Moors between two Castilian forces. The king's prediction of the Moors' strategy proved accurate and they were routed, losing 500 men. Despite Alfonso's orders that his men were not to pursue the retreating Moors beyond the Guadarranque, a large contingent disobeyed and pressed on to the next river, the
Palmones. The Castilians nearly ran into disaster when a fresh Moorish force emerged from Algeciras but were saved by Alfonso's naval force, which rowed up the Palmones to block the Moors. As night fell, the two sides disengaged with the Moors returning to Algeciras and the Castilians encamping on the east side of the Guadarranque. ==Attempt to land on Gibraltar==