named Medinat al-Fath (the City of Victory) was laid out on the upper slopes of the Rock. It is unclear how much of Medinat al-Fath was actually built, as the surviving archaeological remains are scanty. In the late thirteen and early fourteenth centuries the Crown of Castile fought with the Marinids of Morocco and the Nasrids of Granada for control of the Strait of Gibraltar. This conflict () is a major chapter in the history of the Christian reconquest of Spain. Although no documentary account of Gibraltar is available for the period following the creation of Madinat al-Fath, there are reasons to believe that a small fortified town existed in Gibraltar, and that its existence was the direct consequence of the fall of Tarifa in 1292. After the capture of the city, it was expected that the Castilian king Sancho IV would lay siege to Algeciras (though in the event, he did not do so) to hinder the Marinids' communications with the Iberian peninsula. The threatening presence of a Christian stronghold to the west would have made it necessary to set up a garrison to the east of Algeciras. That way, Gibraltar would protect the rearguard of Algeciras and provided a fallback position if the town fell. At the same time, the heights of the Rock of Gibraltar provided an excellent vantage point for monitoring the activities of the Christian fleets in the Straits. It was not until 1309 when Gibraltar's defences were put to the test for the first time in the First Siege of Gibraltar. That year Ferdinand IV of Castile and James II of Aragon joined forces to attack the Muslim Emirate of Granada, targeting Almería in the east and Algeciras, across the bay from Gibraltar, in the west. In July 1309 the Castilians laid siege to both Algeciras and Gibraltar. By this time the latter had a modest population of around 1,200 people, a castle and rudimentary fortifications. They proved unequal to the task of keeping out the Castilians and Gibraltar's Nasrid defenders surrendered after a month. Ferdinand gave up the siege of Algeciras the following February but held on to Gibraltar, expelling the Moors and repopulating it with Christians. A keep and dockyard were built on his orders to secure Castile's hold on the peninsula. Ferdinand also issued a letters patent granting privileges to the inhabitants to encourage people to settle, as it was initially