There is only one Sub-Saharan African country where Spanish is the official language, that country being Equatorial Guinea. The other Spanish speaking areas in Africa are Western Sahara and the far north of Morocco. All countries have a significant number of people speaking other languages, specifically Fang in Equatorial Guinea, Hassaniya Arabic in Western Sahara, and Moroccan Arabic in North Morocco.
Western Sahara became a Spanish colony after the Berlin Conference of 1884, in which European powers divided the African continent into spheres of influence to prevent conflict among themselves.
Northern Morocco, along with a strip of Morocco just north of Western Sahara, became a Spanish protectorate in 1912.