The Byzantine and Arabic sources agree that Abu Hafs was the leader of a group of refugees from al-Andalus, who landed on the island of Crete and conquered it. Traditionally these Andalusians have been described as the survivors of a failed revolt against the emir al-Hakam I of Córdoba in 818. In the aftermath of its suppression, the citizens of the Córdoban suburb of al-Rabad were exiled en masse. Some settled in Fez in Morocco, but others, numbering over 10,000, took to piracy, probably joined by other Andalusians, landed in Alexandria and took control of the city until 827, when they were besieged and expelled by the Abbasid general Abdullah ibn Tahir al-Khurasani. As W. Kubiak points out, however, the supposed origin from Córdoba is contradicted by other sources, which record the presence of Andalusian corsairs in Alexandria as early as 798/9, and their takeover is dated to 814; furthermore, Abu Hafs, who is recorded as their leader, came from a locality that was far from Córdoba. Furthermore, Ibn Hayyan reports that the initial leader of the refugees was not Abu Hafs, but Muhajir ibn al-Qatil. He is echoed by Ibn Sa'id, who also adds that a certain Yahya, leader of the faqihs of Córdoba who had joined the exiles of Rabad, was another leader. It thus appears that Abu Hafs may have become the leader of the Andalusians at Alexandria, for it is only here that he is explicitly named as the leader of the Rabaḍiyyūn, the "rebels of Rabad", by Ibn Khaldun and al-Maqqari.
Conquest of Crete
At some point in the second half of the reign of Byzantine Emperor Michael II, the Andalusians landed on Crete and began its conquest. The exact chronology of the Andalusians' landing in Crete is uncertain. Following the Muslim sources, it is usually dated to 827 or 828, after the Andalusians' expulsion from Alexandria. Byzantine sources however seem to contradict this, placing their landing soon after the suppression of the large revolt of Thomas the Slav, which weakened Byzantine naval defences. Further considerations regarding the number and chronology of the Byzantine campaigns launched against the invaders and prosopographical questions of the Byzantine generals that headed them have led other scholars like Vassilios Christides and Christos Makrypoulias to propose an earlier date,. Christides also suggests that Abu Hafs may have landed on the island in 824/25, on his way to Alexandria, and only returned to conquer the island in 825/26. Under the terms of their agreement with Ibn Tahir, the Andalusians and their families left Alexandria in 40 ships. Historian Warren Treadgold estimates them at some 12,000 people, of whom about 3,000 would be fighting men. According to Byzantine historians, the Andalusians were already familiar with Crete, having raided it in the past. They also claim that the Muslim landing was initially intended as a raid, and was transformed into a bid for conquest when Abu Hafs himself set fire to their ships. However, as the Andalusian exiles had brought their families along, this is probably later invention. The Andalusians' landing-place is also unknown; some scholars think that it was at the north coast, at Suda Bay or near where their main city and fortress Chandax was later built, but others think that they most likely landed on the south coast of the island and then moved to the more densely populated interior and the northern coast.
Establishment of the emirate and campaigns against Byzantium
Abu Hafs was responsible for the construction of Chandax, to where the Andalusians transferred the capital from the inland site of Gortyn, consolidating Muslim rule over the island, and repelling the first, hastily assembled, Byzantine attempts to recover the island under Photeinos and Krateros. He recognized the suzerainty of the Abbasid Caliphate, but he ruled as a de facto independent prince. The Andalusians also occupied several of the Cyclades during these early years. Michael II's admiral Ooryphas managed to evict the Arabs from the Aegean islands, but failed to retake Crete. The overtures of Theophilos to Abd ar-Rahman II of Córdoba, proposing a joint action against the Andalusian exiles, came to nothing, and in October 829, the Andalusians destroyed an imperial fleet off Thasos, undoing much of the work of Ooryphas and opening the Aegean and its coasts to pillage. Later the Andalusians attacked Euboea, Lesbos, and the coasts of the Thracesian Theme, where they destroyed the monastic centre of Mount Latros. They were heavily defeated, however, by the localstrategos, Constantine Kontomytes. After the death of Theophilos in 842, another expedition to recover Crete was launched under the personal leadership of the powerful logothetes and regent Theoktistos. Although it succeeded in occupying much of the island, Theoktistos had to abandon the army due to political intrigues in Constantinople, and the troops left behind were slaughtered by the Arabs. From numismatic evidence, it appears that Abu Hafs died in and was succeeded by his son, Shu'ayb ibn Umar.