Abu Ali Hasan bin Muhammad bin Abbas (d. 423/1032), known as Hasanak had been in service of Mehmud of Ghazna since his childhood. He had gradually risen to the position of a ra'is in Nishapur. In 414/1023, Hasanak went on pilgrimage and allowed himself to be persuaded to return via Cairo and there to accept a robe of honour (khil'a) from the Fatimid Imam az-Zahir. This so offended the Abbasid caliph Kadir that he denounced him as an Ismaili and demanded his execution. After his return to Ghazna, the Abbasid caliph insisted Mehmud that he should have been executed. Mehmud clearly regarded the accusation as unfounded, and went so far as to appoint Hasanak as his vizir in 416/1025 and appeased the Abbasid caliph by sending the robe of honour, and presents received by Hasanak from the Fatimids, which had been burnt in Baghdad. During the last six years of Mehmud's reign, Hasanak exerted a remarkable influence over him, but seems to have opposed his son Masud and supported the descendants of Masud's brother, called Muhammad. This brought about his downfall after Mehmud's death in 421/1030. Hasanak was thus immediately banished to Herat, accused of offending against Masud, and mainly as a result of efforts by the finance minister, Abu Sahl Sawsani, tried on the old charge of being an Ismaili. The Abbasid caliph Kadir also, evidently offended that his wishes in 415/1024 had not been complied with, again interfered. After a long trial, Hasanak was strangled in 423/1032 and his head given in derision to his chief opponent Sawsani; his corpse remained tied to a pillory for seven years.
Meanwhile, a terrible famine broke out in Egypt as a result of a series of bad Niles, and the resultant distress lasted all through 416/1026 and 417/1027. In many cases the starving villages took to brigandage. Even the pilgrims on their way through Egypt were attacked. Regulations were passed to prevent the slaughter of cattle. The camels were scarce as many were killed because it was impossible to provide them with food, and poultry could hardly be procured. The royal treasury was practically depleted, for it was impossible to collect taxes.
Imam az-Zahir once on that perilous time was passing through Fustat when going to one of his palaces. Everywhere he encountered starving, shouting people who cried out: "Hunger, O' Amir al-mominin! hunger. Neither your father nor your grandfather did such things to us. In the name of God, to God we entrust our affair." These cries reflected the feeling that the regime had mishandled the situation. The Imam took its serious notice on the spot, and arranged to distribute food for them, and assured the people to take actions. On the same day, Ibn Dawwas, the market inspector was summoned to the palace; he was accused of causing the famine and blamed for bringing the town to the verge of violent outburst. The people rebuked him and said: "A document in your handwriting is evidence on your part, which serves against you that you undertook upon yourself to provide the town with bread and wheat until the time of the new harvest." Following this conversation, the millers were permitted to buy wheat from granaries (makaazin) at a fixed price of one tillis (one tillis was equivalent to 67.5 kg.) for 2.5 dinars, and the price of a load of flour was determined at 4 dinars. The price of bread was fixed at two and half ratls for dhiram. The prices established by the market inspector were considerably lower than those of the free market. The same was applied to bread, following the sealing of the granaries, two ratls of black bread were sold for 1.5 dhiram. These swift measures brought great deal of relief. Further punitive actions were taken by the market inspectors against several flour merchants (qammahun), including a prominent member of the trade.
Later in a year, however, there was a good inundation, called ziyadat al-nil (the plentiude of the Nile) and this restored plenty, so that the country was once more under normal conditions and order was restored.