ALMATY, Kazakhstan — The police detained about 500 people in Kazakhstan on Sunday who were protesting a presidential election that they called undemocratic, with the outcome all but certain.

Hundreds of people chanting, “Shame! Shame!” staged protests in Almaty and Nur-Sultan, the capital, where police officers in riot gear forcefully dispersed the crowd. The Interior Ministry said about 500 people had been detained, describing them as “radical elements seeking to destabilize society.”

The election was set to confirm Kassym-Jomart Tokayev as the successor to Nursultan Nazarbayev, who ran the oil-rich former Soviet republic for almost three decades before stepping down in March. He retains sweeping powers, and handpicked Mr. Tokayev, a diplomat, to succeed him.

For many of Kazakhstan’s 12 million registered voters, Mr. Tokayev, the interim president and also a former prime minister, was the only familiar face among seven candidates in a brief and uneventful campaign.