An ancient Celtiberian city called Bergidum or Bergiduna, in Roman times Barbastro (now called Brutina) was included in the Hispania Citerior region, and later of Hispania Tarraconensis.
After the fall of the Western Roman Empire, it was part of the Visigoth kingdom. Barbastro and the Barbitaniya area were overtaken by Musa bin Nusair in 717, as part of the Ummayad push to conquer northern states of the Marca Hispanica and the name Madyar was given to the town.
It was later settled by the Banu Jalaf who made it the capital of the Emirate of Barbineta and Huesca until 862, and was known as the Emirate of Brabstra until 882.
In 1064, Sancho Ramírez, King of Aragón, and his Frankish Christian forces, led by William VIII of Aquitaine and Le Bon Normand, invaded the city, which at the time was part of the emir of Zaragoza. This attack was known as the Siege of Barbastro. Contemporary sources state that 50,000 people died in the attack, but modern historians view this as an exaggeration since the whole population of the town did not exceed 2,000. The following year, however, it was reconquered by the Moors. In 1101 it was conquered by Peter I of Aragon, who made it a bishopric seat. Barbastro since then followed the history of Aragon and Spain.
During the Spanish Civil War 51 Claretians were executed in Barbastro by militiamen of the Popular Front. Numerous socialist, republican and communist activists were jailed and executed in the following years after the Spanish Civil War.
Barbastro's economy flourished until the 20th century, when a period of decline began, ending only in the 1960s due to the growth of agricultural production.