Why was Morocco named Morocco?

The English name "Morocco" originates from, respectively, the Spanish and Portuguese names "Marruecos" and "Marrocos". These, in turn, derived from "Marrakesh", the medieval Latin name for the former Almoravid dynasty and Almohad Caliphate capital from ancient Morocco.