In 395/1004, al-Hakim faced the most serious challenge to his authority against the rebellion that shooked and rocked the foundation of his state. This was the rebellion of Abu Raqwa, an Umayyad prince who united the forces of Berbers of Zanata with those of the Arab tribe of Banu Qorra to lead them against the Fatimids. Little is known of Abu Raqwa's background. Most of the historians gave his name as Walid bin Hisham, and Abu Raqwa was his nickname given him by the Egyptians. The word raqwa means "leather bag", in which travellers, especially the Sufis, carried water during journey. He was an Umayyad prince from the line of Marwan bin Hakam. In his twenties, he fled from Spain when Mansur bin Amir took over power and began persecuting members of the Umayyad family. He travelled to Maghrib, Egypt, Yamen, Mecca and Syria; testing the possibility of creating a group strong enough to support the Umayyad cause. At length, he succeeded to generate a large following in Maghrib and proclaimed himself as an amir.
Besides the rooted opposition of Zanata and the dissatisfaction of Banu Qorra with the Fatimids, the economic factors also appears to have been the main cause behind the rebellion of Abu Raqwa. The province of Barqa in Maghrib was very poor, and its treasury was even insufficient to supply the needs of the small army which al-Hakim sent in 391/1000 to restore Fatimid suzerainty in Tripoli. Its commercial life was limited and its income depended upon its limited agricultural output. The whole of Maghrib preceding the rebellion was caught with economic crisis, resulting a sort of catastrophe in 395/1004. Ibn Idhari (d. 712/1312) writes in "Akhbar al-Andalus wa'l Maghrib" (1st. vol., p. 256) that, "In 395/1004, there was a catastrophe in Africa. The poor died and the money of the rich vanished. Prices rose and food became impossible to find. The people of Badia left their homes. Houses became empty and there was no one to occupy them. With all this there was a plague of cholera." Abu Raqwa understood the difficulties of the tribesmen, their overwhelming desire to solve their problems, and therefore, he concentrated his effort to this point. The situtation turned in his favour as an effective tool of his rebellion. When the people agreed to follow his rebellious leadership, the first pact he executed with the people concerning the booty and gains resulting from war. It was resolved to divide the booty into three shares: one for each tribe and one third to be retained under Abu Raqwa's control in order to form a treasury to help during the war. He also promised to give the chiefs the palaces and houses of the Fatimid state in Cairo and other fertile regions in Egypt.
After being assured himself of sufficient support from the two principal tribes, Abu Raqwa canvassed neighboring districts, where he delivered speeches about Islam in a revolutionary manner. The tribesmen were fascinated by his eloquence, and assembled under his leadership against the Fatimids. Sandal, the Fatimid chief of Barqa had immediately reported to al-Hakim and asked permission to campaign against him. According to Ibn Athir (9th vol., p. 82), "Al-Hakim, who apparently did not realize the urgency of the problem, neither gave permission nor sent help but recommended diplomacy, not militant stance as a solution." Sandal's action failed, and Abu Raqwa with his troops swiftly marched to invade the city of Barqa. Sandal and his troops met them outside the city, and was subdued after a fierce fighting. Sandal retreated and barricaded himself inside the city. Sandal also contacted Ibn Taybun, the chief of the Berber tribe of Lawata, who came to the rescue and forced Abu Raqwa to break the siege, but failed to defeat him. Abu Raqwa then inflicted a heavy defeat on Lawata's forces and got the loss of many fighters including Ibn Taybun. The inhabitants of Barqa with their chief Sandal took advantage of Abu Raqwa's temporary withdrawal from their city, and strongly fortified its walls, digging huge trenches around them and storing as much food and supplies as they could. When Abu Raqwa returned to the siege, he found the city in a much stronger position to defend than before. Several months of siege, he failed to convince Sandal to surrender. Meanwhile, al-Hakim sent an army of five thousand men under the leadership of Yanal to relieve Barqa. Yanal had to cross considerable stretch of desert before he reached Barqa, and Abu Raqwa sent a body of cavalry across the route to fill in the wells. He then waited at the point farthest from Egypt to meet Yanal's forces, who arrived tired, exhausted and thirsty. Yanal was defeated and was scourged to death. Abu Raqwa sacked his all equipments and supplies, and returned to Barqa. Sandal, together with his family, fled to Cairo. In the month of Zilhaja, 395/October, 1005, Abu Raqwa captured Barqa, and declared himself amir al-mominin, and adopted the title of al-Nasir li-Dinillah (the assistant of God's order). This was struck on the coinage too, and the khutba was read in his name and the Sunni law was declared. Al-Musabbihi (d. 420/1029) writes that Abu Raqwa's supporters regarded him as a caliph.
About a year after his occupation of Barqa, Abu Raqwa was driven out by the threat of famine and plague. He and his supporters left Barqa as if they were migrating from one land to another, and proceeded towards Alexandria. Al-Hakim began his preparations to quell the rebellion, and appointed Fazal bin Saleh to arrange a large force to meet Abu Raqwa in the field. Meanwhile, a news arrived of Abu Raqwa's movement towards Alexandria. Fazal sent a detachment at the command of Qabil to intercept the rebels, and prevent them from reaching the city. The two armies met in Dhat al-Hamam in Alexandria, where Abu Raqwa won a victory over Qabil. Thence, Abu Raqwa resumed his march towards Alexandria. He besieged it for several months, provoking extreme alarms in Cairo, and a large force had been dispatched from Cairo in command of Fazal bin Saleh. Abu Raqwa failed to capture Alexandria, so he turned towards Cairo. He reached at Fayyum and camped to plan the final blow against the Fatimids. Al-Hakim raised reinforcement of four thousand horsemen at the command of Ali bin Falah to Jiza to prevent Abu Raqwa's troops from raiding areas close to Cairo. Knowing this, Abu Raqwa sent a division of his troops which ambushed Ali bin Falah, killed many of his men. Skirmishes between the two forces continued until they finally met at Ra's al-Barqa in Fayyum district.
It should be noted that a secret pact between Abu Raqwa and the Bedouin chiefs in the Fatimid forces had stipulated that when he would attack, they would withdraw from Fazal bin Saleh's side to create fear and confusion. Fazal was fully aware of this, and on the day of the battle, he summoned all the Bedouin chiefs to his tent. When the attack took place, the Bedouin chiefs, being the prisoners virtually in Fazal's tent, were unable to play their part in accord with the pact with Abu Raqwa, and their troops, unaware of their masters' pact with Abu Raqwa, fought fiercely. Expecting a victory, the troops of Abu Raqwa were easily ambushed and defeated, and he himself fled to the south, and then to Nubia, a large country streching from Aswan to Khartoum, and from Red Sea to the Libyan desert. Abu Raqwa reached at Dumqula, the capital of Nubia, where he pretended to be an ambassador of the Fatimid at the court of the Nubian king. Fazal followed close behind to the Nubian frontier and managed to find out Abu Raqwa, and took him prisoner in 397/1004. He was brought to Cairo, and was paraded through the streets. Ibn Qalanisi (d. 555/1160) writes in "Tarikh-i Dimashq" (p. 65) that Abu Raqwa had written a poetical letter to al-Hakim, begging him for mercy, but al-Hakim refused pardon. But al-Musabbihi (d. 420/1029) as quoted by Makrizi in "Itti'az" (p. 396) however refutes it and suggests that al-Hakim intended to pardon Abu Raqwa as al-Hakim had personally told him while talking about Abu Raqwa, "I did not want to kill him and what happened to him was not of my choosing." Ibn Athir (9th vol., p. 84) writes that, "Abu Raqwa died from humiliation and the cruel treatment during the parade, but was not executed." It transpires that al-Hakim did not wish to execute him and was waiting the termination of the parade to grant him mercy, but he was died.
The rebellion of Abu Raqwa lasted for two years, which almost sucked away the national economy and depleted the royal treasury. In 398/1005, the Nile rising only 16 yards and 16 fingers flow with the result that there was a great rise in prices and hardship. The single bread (al-khubz) became so dear that it could be obtained with great difficulty. It was followed by disease and plague together with malnutrition. Al-Hakim immediately exempted the taxes and formulated strict measures to cope with the situation and instituted death penalty for those who inflated prices or hoarded commodities, which produced the desired effect very soon.