Ever since Irans constitutional revolution in 1906, the PM is directly selected by the Shah and then approved by the Iranian parliament. This was the case from 1906 until 1979 when the Shah left Iran.
So, saying that Mossadegh was democratically elected as all media also does, is fully incorrect. Mossadegh, just like other prime ministers before him, and after him, were all selected by the Shah. Mossadegh was not more nor less democratically elected that the tens of PM before him and the tens of PM after him.
About the role of the CIA in overthrowing him and putting back the Shah, there are two schools of believe:
- CIA overthrew Mossadegh putting the Shah back to power
- That CIA had no role and that they are lying about it
I would recommend these articles:
And I would recommend this book:
That CIA having a role in overthrowing Mossadegh may be the truth according to the media and the CIA itself dying to get credit for it in order to show that they were an effective intelligence organization. But in the academic sphere, the role of CIA is much debated and by many believed to be fully incorrect.