In Egypt, al-Mahdi abandoned the likely choice to go to Yamen as expected by his entourage. This turned out to be a very wise decision, since in Yamen he would have risked the Abbasid confrontation and the menace of the rebellious Qarmatians. On the eve of his departure from Egypt, al-Mahdi revealed his intention of going to Maghrib, and few persons who accompanied him had registered disappointment, notably dai Firuz. W.Ivanow (1886-1970) writes in "Brief Survey of the Evolution of Ismailism" (Holland, 1952, pp. 13-14) that, "Before his move to the remote West, al-Mahdi, according to the Ismaili tradition, had the choice of going to the Yamen where Ibn Hawshab, his able dai, had great success. But al-Mahdi was a clever and talented politician who could realize that the Yamen was nothing but a backwater. He therefore preferred the more risky, yet more promising Maghrib, i.e., N.W. Africa. Here the diplomatic and political talent of the Fatimids was severely tested in their dealings with the Berber tribes. As with all nomads everywhere, these people had their own mentality, their own world of ideas."
While the caravan of al-Mahdi was stirring between Egypt and Tahuna, they were attacked by the Berbers, who looted the caravan and took away some baggages of Imam's books belonging to the Holy Koran, interpretations, history etc. It grieved al-Mahdi much more than other things. When later on, al-Qaim marched in his first campaign against Egypt in 301/913, he brought the brigands and recovered the lost books. According to "Iftitahu'd-Dawa" (comp. in 346/957), al-Mahdi said on that occasion: "Even if this campaign had been undertaken merely to regain these books, this would have been worth while."
The caravan of al-Mahdi went to Tripoli, whose governor made an unsuccessful attempt to arrest him. Al-Mahdi thus divided his caravan into two groups. He sent forward Abul Abbas towards the Katama tribe to gauge the situation as well as to make an advance tidings of his arrival. Abul Abbas reached Kairwan (old Kairouan, now in Tunisia) when the Aghlabid ruler, Ibrahim bin Ahmad had died in 291/903 and was succeeded by Zaidatullah. Abul Abbas was not able to escape suspicion, and was ultimately arrested and tried. He denied all connection with al-Mahdi, insisting that he was an ordinary merchant. He was, nevertheless, imprisoned and the news about this reached to al-Mahdi.
Al-Mahdi went to Kastilla province after knowing the arrest of Abul Abbas and made a junction for few days at Tuzar. When he made sure that there was no possibility of Abul Abbas getting free, he changed his route and went as a merchant to Sijilmasa, the capital of the Midrarite Berber, and stayed in a house hired from a certain Abul Habsha.
Sijilmasa (the old Silhmasa) was an ancient town of Morocco, the capital of Tafilalat. It was built about 200 miles of Fas, on the outskirts of the Sahara and on the left bank of the Wadi Ziz. It was founded in 140/758 and beginning with 155/771, the town and its territory were governed by the Miknas dynasty of the Midrarite. Sijilmasa was situated in the middle of a plain with fertility, because of well watered and was surrounded by gardens and orchards which stretched along the Wadi Ziz. It grew in abundance the most delicious varities of grapes and dates. Among the crops included cotton, cumin, carraway and henna which were exported into the whole Maghrib.
In Sijilmasa, al-Mahdi procured his friendship with the governor, al-Yasa bin Midrar (883-910). When the governor received a letter of Ziadatullah, he put al-Mahdi under house arrest in his sister's residence for about 5 years.