Ever since the Battle of Covadonga in Asturias in 722, the northern Christian kingdoms had kept alive their hopes of “Reconquista” (the struggle to take back control of the Iberian peninsula from the Moors) and, over the centuries, had been making increasing inroads into Moorish Territory.[

With the collapse of the Almohade dynasty after their defeat by the Christians at the Battle of Las Navas de Tolosa in 1212, the Moorish hold on al-Andalus (which had once extended across most of Iberia) was reduced to the Nasrid Kingdom of Granada in the south.

The Nasrids had to rely on the support of the Marinids of North Africa for control of the passage across the Strait and, between 1275 and 1294, allowed them to hold Algeciras and Gibraltar for themselves.

In the struggle for control of the Strait, Alfonso X of Castilla-León had taken the western town of Tarifa in 1292. Two years later, his son Sancho IV entrusted its defence to Don Alonso Pérez de Guzmán who would receive the nickname “Guzmán el Bueno” for his actions.

In December 1308, the kings of two rival Christian kingdoms – Fernando IV of Castilla-León (son of Sancho IV) and Jaime II of Aragón – signed the Treaty of Alcalá de Henares whereby they agreed to put aside their differences and engage in a joint venture against the kingdom of Granada, dividing the conquered lands between them. They were confident that the Marinids would stay neutral since they and the Granadines were not on good terms at the time.

It was decided that the Castillians would attack Algeciras in the Bay of Gibraltar in the west of the Granadine kingdom, while the Aragonese would take the port city of Almeria in the east.

Fernando IV gathered his Castillian troops in Seville from where they made their way overland and by ship to Algeciras, setting siege to it in July 1309 while the Aragonese attacked Almeria a month later.

However, in spite of the blockade imposed by ten Aragonese galleys under Admiral Gisbert de Castellnou which had joined the small Castillian fleet in the Bay, help and supplies kept reaching the Moors in Algeciras by sea from Gibraltar.

Realising that his efforts at trying to weaken the defenders of Algeciras were being undermined, Fernando IV sent Don Alonso Pérez de Guzmán together with other knights and nobles at the head of a contingent of Sevillian troops to besiege and take Gibraltar.

Some went overland to attack the town from the direction of the isthmus. Others sailed across the bay, landing on the red sands just south of the town and proceeded up the slopes to complete the encirclement. On the heights above the castle, Don Alonso Pérez de Guzmán had a strong tower built on which he placed two siege-engines which could hurl large stones against the walls of the Castle, and into the Town below it. The histories don’t specify what type of engines were used but we do know that the tower itself became known as “la Torre de Don Alonso“.

The Mangonel used the tension in twisted ropes to swing the lever The Onager used the tension in a bent lever which would straighten sharply when released The Trebuchet used heavy weights on the short arm of the lever to swing the longer arm at high speed

The houses, the towers, and the numerous defences were battered but the Moors continued to repair the damage, defending the place bravely, and holding out for a whole month. In the end they were obliged to surrender and asked only that they be set free and allowed to leave for Africa. Don Alonso sent a message to the King, that he might personally take possession of the place.

Fernando IV entered the town, gave thanks to God for the achievement and inspected the defences. He stayed two days and gave orders for the walls and towers that had been destroyed by the siege-engines to be repaired, and for a dockyard to be provided as a safe haven for the galleys on the beach below the town with defensive walls and a strong three-storey tower to stop enemy ships from getting close. The dockyard area would later become known as La Barcina and is now Casemates Square.

The 1125 Moorish inhabitants of the Rock were forced to leave. Most went across the Strait to Ceuta. The “Chronicles of Fernando IV” says that as they were leaving, a very old Moor turned to the King and said:

“Sire, what do you have against me to throw me out of this place? Your great-grandfather, King Fernando, took Seville and threw me out of there. So I moved to Jerez. Then, your grandfather, King Alfonso, took Jerez and threw me out of there. So I moved to Tarifa. Your father, King Sancho, then took Tarifa and threw me out of there. So I came to live in Gibraltar thinking that in no Moorish place on this side of the sea would I be safer than here. Seeing that I cannot stay in any of these places, I shall cross the sea and find a place where I can end my days safe and in peace.”

The King returned to the siege at Algeciras where the situation quickly deteriorated. He was finding it difficult to raise enough funds for maintaining the siege. Don Alfonso Pérez de Guzmán, with other noblemen, had been killed in a skirmish near Gaucin. Others, including his uncle and one of his brothers, dissatisfied with a venture that allied them to their bitter rivals from Aragón, had abandoned the enterprise. In addition, by mid-January 1310, the weather, which had for three months brought strong westerly gales and heavy torrential rain, took a turn for the worse.

In February 1310, Fernando IV agreed to peace terms with the King of Granada, Muhammad III. In return for being allowed to keep Gibraltar and a couple of other towns; and the payment by the Moorish king of a large sum of gold, he would lift the siege of Algeciras. 

Jaime II of Aragón was left with no option but to retreat from Almeria where he had been having litlle success anyway.

Before he left, Fernando IV appointed Alonso Fernandez de Mendoza as Governor of Gibraltar (its first non-Moorish Governor) and left troops, arms, and supplies for its defence.

Fernando IV realised that he was leaving Gibraltar as an isolated outpost. The nearest Castillian town overland was Jerez de la Frontera through hostile Moorish territory. The only way it could receive supplies was by sea from Tarifa along the Moorish-controlled Strait. Accordingly, he granted Gibraltar a special Charter of Rights (a “Carta Puebla”) to encourage people to stay there in spite of the dangers.

Among other things, his Charter of Rights established:

a town council with mayor, justices and officials;
freedom from taxes on goods imported for the use of the town;
low taxation on money raised from ships captured and from the ransom of captives;
the right to raise funds for themselves through charging ships berthing
or anchoring and through enterprises like salt-production and tuna-fishing (almadrabas);

specific high wages for those engaged in defence duties.

In addition, in order to attract more people to settle on the Rock, he made it a special place of sanctuary so that any criminal or delinquent (including swindlers, thieves and murderers), any servant who ran away from his master or wife who ran away from her husband could reside in Gibraltar for a year and a day and therafter be pardoned and free from any punishment. The only exceptions to this were traitors and those who committed a crime on the Rock itself.

In the end, these measures had the effect of turning Gibraltar into a kind of military prison, poorly populated and badly defended; its inhabitants turning to small-scale piracy to make money out of the seized ships and then selling their captives for ransom.