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

Al-Hasan ibn Muhammad ibn al-Qasim (Arabic: الحسن بن محمد بن القاسم), known by the sobriquet al-Hajjam (الحجام, lit. 'the barber') 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.

## Genealogy

Idrisid dynasty :
* Emirs of Morocco
* Caliphs of Córdoba
* Emirs of Algericas
* Emirs of Málaga
| | | | | | | | | | | | | | | | | | | | | Abd al-Muttalib ibn Hashim | Abd al-Muttalib ibn Hashim | Abd al-Muttalib ibn Hashim | Abd al-Muttalib ibn Hashim | Abd al-Muttalib ibn Hashim | Abd al-Muttalib ibn Hashim |
| | | | | | | | | | | | | | | | | Abu Talib ibn Abd al-Muttalib | Abu Talib ibn Abd al-Muttalib | Abu Talib ibn Abd al-Muttalib | Abu Talib ibn Abd al-Muttalib | Abu Talib ibn Abd al-Muttalib | Abu Talib ibn Abd al-Muttalib | | | Abdullah ibn Abd al-Muttalib | Abdullah ibn Abd al-Muttalib | Abdullah ibn Abd al-Muttalib | Abdullah ibn Abd al-Muttalib | Abdullah ibn Abd al-Muttalib | Abdullah ibn Abd al-Muttalib |
| | | | | | | | | | | | | | | | | | | | | | | | | Muhammad ibn Abd Allah | Muhammad ibn Abd Allah | Muhammad ibn Abd Allah | Muhammad ibn Abd Allah | Muhammad ibn Abd Allah | Muhammad ibn Abd Allah | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | Ali ibn Abi Talib | Ali ibn Abi Talib | Ali ibn Abi Talib | Ali ibn Abi Talib | Ali ibn Abi Talib | Ali ibn Abi Talib | | | Fatima bint Muhammad | Fatima bint Muhammad | Fatima bint Muhammad | Fatima bint Muhammad | Fatima bint Muhammad | Fatima bint Muhammad | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | al-Hasan ibn Ali | al-Hasan ibn Ali | al-Hasan ibn Ali | al-Hasan ibn Ali | al-Hasan ibn Ali | al-Hasan ibn Ali |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | al-Hasan ibn al-Hasan | al-Hasan ibn al-Hasan | al-Hasan ibn al-Hasan | al-Hasan ibn al-Hasan | al-Hasan ibn al-Hasan | al-Hasan ibn al-Hasan |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Abd Allah ibn al-Hasan | Abd Allah ibn al-Hasan | Abd Allah ibn al-Hasan | Abd Allah ibn al-Hasan | Abd Allah ibn al-Hasan | Abd Allah ibn al-Hasan |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Idris I al-Akbar r. 788-791 | Idris I al-Akbar r. 788-791 | Idris I al-Akbar r. 788-791 | Idris I al-Akbar r. 788-791 | Idris I al-Akbar r. 788-791 | Idris I al-Akbar r. 788-791 |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Idris II r. 803-828 | Idris II r. 803-828 | Idris II r. 803-828 | Idris II r. 803-828 | Idris II r. 803-828 | Idris II r. 803-828 |
| | | | | | | Muhammad I r. 828-836 | Muhammad I r. 828-836 | Muhammad I r. 828-836 | Muhammad I r. 828-836 | Muhammad I r. 828-836 | Muhammad I r. 828-836 | | | | | | | | | Umar ibn Idris | Umar ibn Idris | Umar ibn Idris | Umar ibn Idris | Umar ibn Idris | Umar ibn Idris | | | | | | | | | al-Qasim ibn Idris | al-Qasim ibn Idris | al-Qasim ibn Idris | al-Qasim ibn Idris | al-Qasim ibn Idris | al-Qasim ibn Idris | Dawud r. c. 877 | Dawud r. c. 877 | Dawud r. c. 877 | Dawud r. c. 877 | Dawud r. c. 877 | Dawud r. c. 877 |
| Ali I r. 836-849 | Ali I r. 836-849 | Ali I r. 836-849 | Ali I r. 836-849 | Ali I r. 836-849 | Ali I r. 836-849 | Yahya I r. 849-863 | Yahya I r. 849-863 | Yahya I r. 849-863 | Yahya I r. 849-863 | Yahya I r. 849-863 | Yahya I r. 849-863 | Ali II r. 866-? | Ali II r. 866-? | Ali II r. 866-? | Ali II r. 866-? | Ali II r. 866-? | Ali II r. 866-? | | | Idris ibn Umar | Idris ibn Umar | Idris ibn Umar | Idris ibn Umar | Idris ibn Umar | Idris ibn Umar | | | Ubayd Allah ibn Umar | Ubayd Allah ibn Umar | Ubayd Allah ibn Umar | Ubayd Allah ibn Umar | Ubayd Allah ibn Umar | Ubayd Allah ibn Umar | Yahya III r. ?-905 | Yahya III r. ?-905 | Yahya III r. ?-905 | Yahya III r. ?-905 | Yahya III r. ?-905 | Yahya III r. ?-905 | Muhammad ibn al-Qasim | Muhammad ibn al-Qasim | Muhammad ibn al-Qasim | Muhammad ibn al-Qasim | Muhammad ibn al-Qasim | Muhammad ibn al-Qasim |
| | | | | | | Yahya II r. 863-866 | Yahya II r. 863-866 | Yahya II r. 863-866 | Yahya II r. 863-866 | Yahya II r. 863-866 | Yahya II r. 863-866 | | | | | | | | | Yahya IV r. 905-922 | Yahya IV r. 905-922 | Yahya IV r. 905-922 | Yahya IV r. 905-922 | Yahya IV r. 905-922 | Yahya IV r. 905-922 | | | Ali ibn Ubayd Allah | Ali ibn Ubayd Allah | Ali ibn Ubayd Allah | Ali ibn Ubayd Allah | Ali ibn Ubayd Allah | Ali ibn Ubayd Allah | al-Hasan I al-Hajjam r. 928–930 | al-Hasan I al-Hajjam r. 928–930 | al-Hasan I al-Hajjam r. 928–930 | al-Hasan I al-Hajjam r. 928–930 | al-Hasan I al-Hajjam r. 928–930 | al-Hasan I al-Hajjam r. 928–930 | al-Qasim Kanun r. 937-949 | al-Qasim Kanun r. 937-949 | al-Qasim Kanun r. 937-949 | al-Qasim Kanun r. 937-949 | al-Qasim Kanun r. 937-949 | al-Qasim Kanun r. 937-949 |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hammud ibn Ali | Hammud ibn Ali | Hammud ibn Ali | Hammud ibn Ali | Hammud ibn Ali | Hammud ibn Ali | Abu al-Aysh Ahmad r. 948-954 | Abu al-Aysh Ahmad r. 948-954 | Abu al-Aysh Ahmad r. 948-954 | Abu al-Aysh Ahmad r. 948-954 | Abu al-Aysh Ahmad r. 948-954 | Abu al-Aysh Ahmad r. 948-954 | al-Hasan II r. 954-974 | al-Hasan II r. 954-974 | al-Hasan II r. 954-974 | al-Hasan II r. 954-974 | al-Hasan II r. 954-974 | al-Hasan II r. 954-974 |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Maymun ibn Hammud | Maymun ibn Hammud | Maymun ibn Hammud | Maymun ibn Hammud | Maymun ibn Hammud | Maymun ibn Hammud | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hammud ibn Maymun | Hammud ibn Maymun | Hammud ibn Maymun | Hammud ibn Maymun | Hammud ibn Maymun | Hammud ibn Maymun | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | al-Qasim al-Ma'mun r. 1018-1021, 1023 | al-Qasim al-Ma'mun r. 1018-1021, 1023 | al-Qasim al-Ma'mun r. 1018-1021, 1023 | al-Qasim al-Ma'mun r. 1018-1021, 1023 | al-Qasim al-Ma'mun r. 1018-1021, 1023 | al-Qasim al-Ma'mun r. 1018-1021, 1023 | | | | | | | | | | | Ali al-Nasir r. 1016-1018 | Ali al-Nasir r. 1016-1018 | Ali al-Nasir r. 1016-1018 | Ali al-Nasir r. 1016-1018 | Ali al-Nasir r. 1016-1018 | Ali al-Nasir r. 1016-1018 |
| | | | | | | | | | | | | Muhammad al-Mahdi r. 1035-1048 | Muhammad al-Mahdi r. 1035-1048 | Muhammad al-Mahdi r. 1035-1048 | Muhammad al-Mahdi r. 1035-1048 | Muhammad al-Mahdi r. 1035-1048 | Muhammad al-Mahdi r. 1035-1048 | | | | | | | | | | | Idris I al-Muta'ayyad r. 1035-1039 | Idris I al-Muta'ayyad r. 1035-1039 | Idris I al-Muta'ayyad r. 1035-1039 | Idris I al-Muta'ayyad r. 1035-1039 | Idris I al-Muta'ayyad r. 1035-1039 | Idris I al-Muta'ayyad r. 1035-1039 | Yahya I al-Mu'tali r. 1021-1023, 1025-1026 r. 1026-1035 | Yahya I al-Mu'tali r. 1021-1023, 1025-1026 r. 1026-1035 | Yahya I al-Mu'tali r. 1021-1023, 1025-1026 r. 1026-1035 | Yahya I al-Mu'tali r. 1021-1023, 1025-1026 r. 1026-1035 | Yahya I al-Mu'tali r. 1021-1023, 1025-1026 r. 1026-1035 | Yahya I al-Mu'tali r. 1021-1023, 1025-1026 r. 1026-1035 |
| | | | | | | | | | | | | al-Qasim al-Wathiq r. 1048-1054 | al-Qasim al-Wathiq r. 1048-1054 | al-Qasim al-Wathiq r. 1048-1054 | al-Qasim al-Wathiq r. 1048-1054 | al-Qasim al-Wathiq r. 1048-1054 | al-Qasim al-Wathiq r. 1048-1054 | | | Muhammad I al-Mahdi r. 1047-1053 | Muhammad I al-Mahdi r. 1047-1053 | Muhammad I al-Mahdi r. 1047-1053 | Muhammad I al-Mahdi r. 1047-1053 | Muhammad I al-Mahdi r. 1047-1053 | Muhammad I al-Mahdi r. 1047-1053 | | | Yahya II al-Qa'im r. 1039-1040 | Yahya II al-Qa'im r. 1039-1040 | Yahya II al-Qa'im r. 1039-1040 | Yahya II al-Qa'im r. 1039-1040 | Yahya II al-Qa'im r. 1039-1040 | Yahya II al-Qa'im r. 1039-1040 | Idris II al-Ali r. 1042-1047, 1053-1054/5 | Idris II al-Ali r. 1042-1047, 1053-1054/5 | Idris II al-Ali r. 1042-1047, 1053-1054/5 | Idris II al-Ali r. 1042-1047, 1053-1054/5 | Idris II al-Ali r. 1042-1047, 1053-1054/5 | Idris II al-Ali r. 1042-1047, 1053-1054/5 | Hasan al-Mustansir r. 1040-1042 | Hasan al-Mustansir r. 1040-1042 | Hasan al-Mustansir r. 1040-1042 | Hasan al-Mustansir r. 1040-1042 | Hasan al-Mustansir r. 1040-1042 | Hasan al-Mustansir r. 1040-1042 |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Idris III al-Sami r. 1053 | Idris III al-Sami r. 1053 | Idris III al-Sami r. 1053 | Idris III al-Sami r. 1053 | Idris III al-Sami r. 1053 | Idris III al-Sami r. 1053 | Muhammad II al-Musta'li r. 1054/5 | Muhammad II al-Musta'li r. 1054/5 | Muhammad II al-Musta'li r. 1054/5 | Muhammad II al-Musta'li r. 1054/5 | Muhammad II al-Musta'li r. 1054/5 | Muhammad II al-Musta'li r. 1054/5 | Abd Allah ibn Idris | Abd Allah ibn Idris | Abd Allah ibn Idris | Abd Allah ibn Idris | Abd Allah ibn Idris | Abd Allah ibn Idris |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Muhammad ibn Abd Allah | Muhammad ibn Abd Allah | Muhammad ibn Abd Allah | Muhammad ibn Abd Allah | Muhammad ibn Abd Allah | Muhammad ibn Abd Allah | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Muhammad ibn Muhammad al-Idrisi | Muhammad ibn Muhammad al-Idrisi | Muhammad ibn Muhammad al-Idrisi | Muhammad ibn Muhammad al-Idrisi | Muhammad ibn Muhammad al-Idrisi | Muhammad ibn Muhammad al-Idrisi | | | | | | |