After he took the throne, he negotiated a treaty with Alfonso X of Castile, in which Castile agreed to end support for the Banu Ashqilula in exchange for payments. When Castile took the money but maintained its support for the Banu Ashqilula, Muhammad turned towards Abu Yusuf of the Marinids. The Marinids sent a successful expedition against Castile, but relations soured when the Marinids treated the Banu Ashqilula as Muhammad's equals. In 1279, through diplomatic manoeuvring, Muhammad regained Málaga, formerly the centre of Banu Ashqilula power. In 1280, his diplomacy backfired when Granada faced simultaneous attacks from Castile, the Marinids and the Banu Ashqilula. Attacked by his more powerful neighbours, Muhammad exploited the rift between Alfonso and his son Sancho, as well as receiving help from Volunteers of the Faith, soldiers recruited from North Africa. The threat subsided when Alfonso died in 1284 and Abu Yusuf in 1286; their successors (Sancho and Abu Yaqub, respectively) were preoccupied with domestic matters. In 1288 the Banu Ashqilula emigrated to North Africa at Abu Yaqub's invitation, removing Muhammad's biggest domestic concern. In 1292, Granada helped Castile take Tarifa from the Marinids on the understanding that the town would be traded to Granada, but Sancho reneged on the promise. Muhammad II then switched to the Marinid side, but a Granadan–Marinid attempt to retake Tarifa in 1294 failed. In 1295, Sancho died and was succeeded by Ferdinand IV, a minor. Granada took advantage by conducting a successful campaign against Castile, taking Quesada and Alcaudete. Muhammad also planned a joint offensive with Aragon against Castile, but he died in 1302 before the operation took place.