Nazarbayev, 78, has led the oil-rich Central Asian nation since 1990 after its independence from the Soviet Union.
He said in a televised address: "I have taken a decision, which was not easy for me, to resign as president", Reuters reported.
In the final years of his reign, a veritable personality cult emerged around Kazakhstan's president.
The President also cast himself as a relatively enlightened ex-Soviet leader, at least in comparison with some of his more despotic Central Asia neighbours.
Under the constitution, "in case of an early resignation of the incumbent president his powers will be transferred to the chairman of the Senate until his term ends", Nazarbayev said, noting that then the country would hold the election.
Nazarbayev will remain a force in Kazakh affairs.
The resignation comes just weeks after the ageing strongman dismissed the country's government. In 2010, Mr Nazarbayev was unanimously elected the nation's leader for life.More news: New Zealand PM Ardern vows never to speak killer's name
More news: Man City fight back to keep quadruple bid alive
More news: Microsoft combines video gaming and Azure to take on Amazon
She credited Nazarbaev with being behind the initiative to create the Eurasian Economic Union and said he had "bolstered cooperation between Russian Federation and Kazakhstan".
A huge country the size of Western Europe, Kazakhstan has vast mineral resources and enormous economic potential.
"The relations between Russian Federation and Kazakhstan won't deteriorate because of this move".
There were hints that this was coming: In February, Nazarbayev quashed resignation rumors that had been churned up by his asking the country's Constitutional Council for guidance on what powers he would retain if he were to step down.
He recalled that Tokayev, who graduated from the Moscow State Institute of International Relations, has a doctorate degree and is fluent in English and Chinese.
Aliev, a top security official and husband of Nazarbayev's eldest daughter Dariga, was widely seen as his successor.
Tokayev has previously served as the foreign minister, deputy prime minister and prime minister, and United Nations deputy secretary-general.
In 2004, Nazarbayev's Nur Otan party retained the seats necessary to control the lower house of parliament in an election widely criticized on the worldwide stage, and, in 2015, Nazarbayev was re-elected with 97.7 percent of the vote. The 55-year-old is now a senator and formerly headed her own political party, while also serving as deputy prime minister.
In those days, Kazakhstan was a backwater region best known for prisons, nuclear testing sites and being the home of the launch facility of the Soviet space program, the Baikonur Cosmodrome.