History
Though the area was inhabited by Berber farmers from Neolithic times, the settlement of Marrakesh wasn't founded until 1062. Thereafter the city grew and became the centre for several powerful regional dynasties.
The city particularly developed under the Saadians, the last great rulers to be based in the city. Marrakesh then formed part of a larger Alaouites kingdom and then part of the The French colonial empire before Morocco gained independence in modern times.
Detailed history
Try the more detailed history of the city on Eric Ross's blog (scroll down to "Marrakech, the imperial capital").
The history of Marrakesh on Wikipedia