The Fatimid Dynasty became very weak for many reasons: the weakness of the Caliphs; the conflicts between the viziers on the throne; the strong famine which happened because of the low level of the Nile; the spread of dangerous diseases (especially plague) and the Caliphs being a game in the hands of the viziers. Then a new danger appeared: the Crusaders came to Egypt and Syria with the excuse of saving the Sacred City of Jerusalem from the Seljuk rulers. In Syria, Nur-Ed-Din Mahmoud (the Islamic warrior) noticed the value of Egypt, so he thought of invading it to siege the Crusaders between two sides. He took the opportunity of the conflict between the two Fatimid viziers (Shawar and Dirgham) to interfere in Egypt's affairs.
Shawar, the Arab governor of Upper Egypt, became a vizier after El-Adil Ruzzik. Dirgham succeeded to be the vizier of Egypt to dismiss Shawar from Cairo. Then, Shawar went to Nur-ed-Din at Damascus and asked his help. Shawar offered to pay the cost of the expedition and promised Nur-ed-Din to pay him a third of the revenue of Egypt if he restored his power in Egypt.
Knowing that Shawar made a treaty with Nur-ed-Din, Dirgham tried to make strong relations with the Crusaders and the King of Jerusalem against Nur-ed-Din and Shawar. Then, supported by a strong army led by Shirkuh and his nephew Saladin, Shawar came to Egypt.
Shirkuh defeated the Egyptians and Crusaders and Dirgham was killed. When Shawar restored his power, he broke all his promises and refused to pay the tribute. But, he made a strong relation with the Crusaders against the Seljuks. Then, Shirkuh insisted that Nur-ed-Din allow him to invade Egypt, because the government of Egypt was very weak and the country enjoyed no security in it. Finally, Nur-ed-Din gave orders to Shirkuh to invade Egypt with 2000 horsemen.
When Shirkuh reached the Nile, at Atfih (south of Cairo), he knew that Amalric left Palestine quickly and went to Egypt as soon as he heard of Shirkuh's move. Amalric's army camped near Fustat, while Shirkuh's army camped at Giza. The two armies met at an area called The Two Gates (El-Baban), south of Minya. Shirkuh defeated Amarlic's army and Shawar's army and the two armies came back to Cairo. But Shirkuh did not follow them. Rather, he went north by a desert route and entered Alexandria without any fight.
Shirkuh appointed Saladin Governor of Alexandria and left with him one half of his army. Then, Shirkuh went with the other half to Upper Egypt in order to collect money. Then, the Crusader and Egyptian armies together with the Christian fleet sieged Alexandria.
Finally, a peace treaty was signed between the Crusaders and Shirkuh. According to this treaty:
a- Both the Crusaders and Shirkuh should leave Egypt to the Egyptians.
b- Alexandria was to surrender to Shawar.
c- Prisoners were to be exchanged.
d- Shirkuh returned with his tired army to Damascus.
When the Seljuks pressed the Crusaders in Palestine, the Crusaders found that it is better to invade Egypt to increase their power. Therefore, the King of Jerusalem entered Egypt for the third time, as an enemy not as a friend. When he arrived at Bilbys, he mercilessly killed a large number of people. After that, he went to Fustat, but Shawar burnt Fustat to prevent the Crusaders from taking it as their camp. The fire lasted for 54 days.
At that time, the Fatimid young Caliph, El-Adid, wrote a letter to Nur-ed-Din, asking him to come to rescue Egypt. Moreover, attached with the letter, El-Adid sent some of his wives' hair as a strong sign of supplication. When the letter reached Nur-ed-Din, he prepared the third expedition, headed by Shirkuh and supported by Saladin. When Shirkuh arrived in Egypt, he defeated the Crusaders and dismissed them. Then, the Caliph El-Adid appointed Shirkuh his vizier after Shawar had been killed because of his treason. Then, the Caliph gave Shirkuh the title of El-Malik-el-Nasr.
Shirkuh stayed two months in his position till he died suddenly. Following Shirkuh was his nephew, Saladin. Two years later, Saladin got rid of the Fatimids completely founding the Ayyubid Dynasty.