The 36-year rule of Ayatollah Ali Khamenei built Iran into a powerful anti-US force, spreading its military sway across the Middle East, while using an iron fist to crush repeated unrest at home.