I am not sure why this is downvoted, because this is what happened in Iran, the islamists took advantage of the 1979's revolution.
Good writeup here: https://www.npr.org/2019/01/31/690363402/how-the-cia-overthr...
Elections where candidates are extensively vetoed by the clergy before being allowed (or not) to run. Even if the population wanted to reduce the role of religion in politics, it isn't allowed to elect people whom the clergy deems too secular.