There are basically three types of election.
(a) The first are the usual ones, which are organised with the aim of confirming the ruling power — and they work.
(b) Elections in which the ruling group misjudges the situation or makes other significant errors, allowing the opposition to capitalise on this and win unexpectedly. This is how Miloš Zeman became president. The same happened with Donald Trump in 2016.
(c) Elections taking place when the ruling power has effectively collapsed, leaving them unable to stop the opposition from taking over. This was the case in the 2020 US presidential election.