In 713, the Teodomiro Pact was signed, referring to the place with the name "Lurqa." Under this pact, the population was integrated into an autonomous territory, along with six other cities, governed by Theudimer (Teodomiro). This lasted until his death when a Muslim reorganization of the state occurred, carried out by Abb-al-Rahman II, who turned the territory into a Córdoba dependency. It led to the formation of the Taifa kingdoms, with the Taifa of Lorca as one of these kingdoms, first created in 1042, when Lorca declared its independence from the emirate of Valencia. Its first governor was Ma'n Ibn Sumadih, its power extending from the city to Jaén and Baza. During the Arab period it was known as "Lurka" and the old part of the town, made up of narrow streets and alley-ways, achieved its present shape under Moorish rule.