Ayatollah Ali Khamenei crushed internal threats during more than three decades in power as Iran’s supreme leader