Morocco asserted its claim on the Sahara in 1957, and the Ifni war proceeded as you mentioned, as well as other battles. In 1965, the UN demanded Spain end its claims in the Sahara. Then, the biggest operation, the Green March in 1975, took place, which led to the Spaniards packing their bags...