This comes from the Latin word barbarus meaning foreign. “Barbary” referred to foreign lands (lands not of ones own). And “barbarian” referred to the people who lived there.
The northern coast of Africa was named “The Barbary Coast” by English speakers after attacks from pirates based in Tripoli and Tunis. The young United States fought two series of battles with these pirates in the early 1800s, including the first ever foreign action of the U.S. Marine Corps.
The ancient Romans named the inhabitants of Northern Africa “berbers,” a form of the word “barbary.”
Since barabas is a relative term (“foreign” to whom?), once has to assume that no one ever referred to themselves as “berber” or “barbarian.” It seems to be a mildly pejorative term used to describe other people.