Why did Kazakh President Nursultan Nazarbayev resign?

Nursultan Nazarbayev ruled Kazakhstan for almost three decades but he has resigned, surprising many.