farfan) were soldiers hailing mostly from the Christian Iberian kingdoms in the later Middle Ages fighting as mercenaries for the various Muslim dynasties of the Western Mediterranean.
These types of arrangements are well known due to the fame of El Cid, and as it was widespread in al-Andalus, it is possible that this habit was passed on to the other side of the Mediterranean in the 12th century.
Units composed entirely of slaves or recently-freed men were relatively common both in North Africa and in al-Andalus, so this theory of the origin of the farfan fits an observable pattern.
The history of Reverter de La Guardia, a Catalan nobleman captured by the Almoravid army on a Spanish battlefield in the 1120s, is one of the earliest examples of a Christian mercenary fighting in North Africa and would support this scenario.
Once in the hostile Maghrebi environment, the Mozarabs would have had little choice but to seek the support of the Almoravid rulers and to enlist as soldiers in their armies.