The Count of Toulouse was the ruler of Toulouse during the 8th to 13th centuries. Originating as vassals of the Frankish kings, the hereditary counts ruled the city of Toulouse and its surrounding county from the late 9th century until 1270. The counts and other family members were also at various times counts of Quercy, Rouergue, Albi, and Nîmes, and sometimes margraves (military defenders of the Holy Roman Empire) of Septimania and Provence. Count Raymond IV founded the Crusader state of Tripoli, and his descendants were also counts there. They reached the zenith of their power during the 11th and 12th centuries, but after the Albigensian Crusade the county fell to the kingdom of France, nominally in 1229 and de facto in 1271.
During the youth of young Louis, his tutor, Torson (sometimes Chorso or Choson), ruled at Toulouse as the first count. In 788, Count Torson was captured by the Basques under Adalric, who made him swear an oath of allegiance to the Duke of Gascony, Lupus II. Upon his release, Charlemagne, at the Council of Worms (790), replaced him with his Frankish cousin, William of Gellone. William in turn successfully subdued the Gascons.