At first dismissed as weak and indecisive, Khamenei seemed an unlikely choice for supreme leader after the death of the charismatic Ayatollah Ruhollah Khomeini.