Al-Hasan al-Hajjam ibn Muhammad ibn al-Qasim

Al-Hasan ibn Muhammad ibn al-Qasim (الحسن بن محمد بن القاسم), known by the sobriquet al-Hajjam (الحجام, ) was the tenth Idrisid ruler of Morocco, although he held only the capital of Fes and its environs.

Al-Qasim descended from a cadet branch of the Idrisid dynasty: his grandfather, al-Qasim, was a younger son of the dynasty's second ruler, Idris II. In 922 or 925 or 928 (medieval and modern sources provide different dates) he rose in revolt against the Fatimid Caliphate's viceroy in Morocco, Musa ibn Abi'l-Afiya, and recovered control of Fes. Two years later, he defeated Ibn Abi'l-Afiya in combat, but was betrayed by Hamid ibn Hamdan, the governor he appointed over Fes, and imprisoned, while Fes was surrendered to Musa.

Ibn Abi'l-Afiya then fell out with Hamid ibn Hamdan and the Fatimids, launching a persecution of the Idrisids, before siding with the Fatimids' enemies, the Umayyad Caliphate of Córdoba in 931. A complicated struggle followed between the Hamid ibn Hamdun, the Idrisids, their rivals from the Abu Sahl family, Musa ibn Abi'l-Afiya, and the Fatimids under the general Maysur. Allied with the Fatimids against Ibn Abi'l-Afiya, Hasan's brother al-Qasim Jannun managed to establish an Idrisid emirate in the Rif Mountains in northern Morocco, before switching his allegiance to the Umayyads in 944.