structural:expansion
Second invasion of Egypt

Al-Mahdi immediately began preparations for a second assault on Egypt, starting with the recapture of Cyrenaica. This was accomplished with the surrender of Barqa after an 18-month siege, in April 917. The expedition against Egypt began on 5 April 919, when al-Qa'im, placed in sole command of the campaign, set out from Raqqada. Although Alexandria's Abbasid garrison had been reinforced, it was abandoned without battle upon the arrival of the Fatimid army. Having already acknowledged Fatimid sovereignty during the first invasion and hence now considered in revolt, the city was sacked by the Fatimid troops.

Once again, the Abbasids concentrated at defending the Nile crossing at Giza. Al-Qa'im did not move against Giza, however, giving time for Abbasid reinforcements under Mu'nis al-Muzaffar to arrive. On 12 March 920, the Fatimid invasion fleet was destroyed by the Abbasid admiral Thamal al-Dulafi, crippling the invaders. Pressed for supplies, al-Qa'im repeated his manoeuvre of 914, occupying the Fayyum Oasis. Fatimid troops also succeeded in occupying much of Upper Egypt, cutting off the grain supply to Fustat.

For an entire year after that, both sides avoided open conflict, and engaged rather in a diplomatic and propaganda battle. Mu'nis offered promises of safe-conduct as well as recognition of the Fatimids as autonomous rulers of Ifriqiya in the style of the Aghlabids, if al-Qa'im and his father submitted to the Abbasid caliph. Al-Qa'im rejected these overtures, reiterating the Fatimid claims to universal dominion as the rightful heirs of Muhammad. He also sent letters to Fustat urging the Egyptians to rise in revolt, and to the two holy cities of Islam, Mecca and Medina, demanding recognition of the Fatimid claims to sovereignty over the Islamic world.

Finally, in late spring 921, the Abbasids launched their attack, capturing Alexandria and then moving onto Fayyum. Cut off in the oasis, al-Qa'im was forced to abandon all his heavy equipment, and with his army crossed the desert to Barqa.