Why does Morocco have a king?

Morocco has had a king ever since its establishment as a unified polity in the 700s C.E. It has never experienced any non-monarchical form of government, even though it has been under numerous different dyansties.