Morocco has been independent since they gained the status of being so in 1956. Initially, in 1912, there was a Moroccan Crisis and the Agadir Crisis which led to the Treaty of Fez being signed. That divided Morocco into two different places, the French and Spanish protectorates.
Then, in 1956, following 44 years of being ruled over by the French, Morocco was able to regain their complete independence from the nation of France. Not long after that, they regained the majority of their other territories too that had been under Spanish control all that time.