The father of al-Mahdi Muhammad was the Imam
al-Mutawakkil al-Mutahhar bin Yahya, who held the
imamate of Zaidiyyah in the late 13th century with varying success. After al-Mutawakkil's death in
Hajjah in 1298, al-Mahdi Muhammad claimed the succession, although the imamate was not strictly speaking hereditary. His term as imam is counted from either 1298 or 1301. When he acceded, the
Sunni Muslim Rasulid Dynasty was still in a strong position, and dominated most of Yemen, including
San'a. By and by, however, the imam was able to expand his territory in the highland. The population in the Sheref district suffered from Rasulid maladministration. In 1311, they heeded the summons of the imam, who started a military campaign against the oppressors. A major battle was fought in Yemen on 26 December 1311 where the troops of the Rasulid Sultan
al-Mu'ayyad Da'udsultan were crushed. The Rasulid defeat resulted in a ceasefire agreement, which was transformed into a ten years peace in October 1312. Upper Sheref and a number of other places were acknowledged as belonging to al-Mahdi Muhammad, who furthermore received 3,000 ducats per year from the sultan's treasury. ==Conquest of San'a==