The County of Barcelona (, ) was a polity in northeastern Iberian Peninsula, originally located in the southern frontier region of the Carolingian Empire. In the 10th century, the Counts of Barcelona progressively achieved independence from Frankish rule, becoming hereditary rulers in constant warfare with the Islamic Caliphate of Córdoba and its successor states. The counts, through marriage, alliances and treaties, acquired or vassalized the other Catalan counties and extended their influence over Occitania. In 1164, the County of Barcelona entered a personal union with the Kingdom of Aragon. Thenceforward, the history of the county is subsumed within that of the Crown of Aragon, but the city of Barcelona remained preeminent within it.
Within the Crown, the County of Barcelona and the other Catalan counties progressively merged into a polity known as the Principality of Catalonia, which assumed the institutional and territorial continuity of the County of Barcelona.
Origins
Its origins date back to the early 8th century, when Muslims took control of the northern territories of the Visigothic Kingdom in Hispania and modern-day northeastern Spain and southern France. After turning back deep Muslim incursions, the Frankish Empire under the Carolingian monarchs, created the hystoriographycally Marches of Gothia and Hispania progressively. This was achieved by taking over the territories of Septimania that the Moors invaded in the 8th century and from these, those territories surrounding the Pyrenees and specially the northeast of the Iberian Peninsula. These eastern Iberian territories were repopulated with people from the March of Gothia.
This resulted in the formation of an effective buffer zone between the Muslim Iberian peninsula and the Duchy of Aquitaine and Provence.
Frankish rule
The area was dominated by the Franks after the conquest of Girona (785) and especially when, in 801, the city of Barcelona was conquered by King Louis the Pious of Aquitaine, and was incorporated into the Frankish kingdom. The county of Barcelona was established there, reporting to the Frankish king. The first count of Barcelona was Bera (801–820).
Initially, authority for the county rested on the local aristocracy. However, the policies Bera adopted in an effort to maintain peace with Muslim ruled Al-Andalus, resulted in him being accused of treason before the king. After losing a duel, according to the Visigothic legislation, Bera was deposed and exiled, and the government of the county went to Frankish nobles, such as Rampon or Bernard of Septimania. However, the Visigothic nobility regained the king's confidence with the appointment of Sunifred I of Urgell-Cerdanya as count of Barcelona in 844.
Autonomy and unification
Nevertheless, the ties of the Catalan counties to the Frankish monarchy had weakened. Autonomy was strengthened when the county families began to affirm their inheritance rights. This move was accompanied by a unification process among counties to form larger political entities. Count Wilfred the Hairy, son of Sunifred and the last count appointed by the Frankish king, oversaw this movement. He united a number of counties under his command and passed them on as an inheritance to his children. Wilfred later died at the hands of Muslims. Although he divided his counties among his children, the core formed by the counties of Barcelona, Girona and Osona remained undivided (although some historians, such as Ramon Martí, question whether Girona was kept initially under the domain of the children of Wilfred, and suggests that the County of Empúries dominated the county until the year of 908).
Independence
During the 10th century, the counts of Barcelona strengthened their political authority and further distanced themselves from Frankish influence. In 985 Barcelona, then ruled by Borrell II, was attacked and burned by Muslims, led by Almanzor. The count took refuge in the Montserrat mountains, awaiting help from the Frankish king, which never arrived, resulting in resentment. In 988, the reign of the Carolingian dynasty ended and was replaced by the Capetian dynasty. Borrell II was required to swear allegiance to the new Frankish king, but there is no evidence that the count acceded to the call, as the Frankish king had to go north to resolve a conflict. This has been interpreted as the starting point of effective independence of the county. The relinquishment of any possible French claim of feudal overlordship was obtained by James I in the Treaty of Corbeil (1258).