Lebanon's parliament on Monday elected Michel Aoun, an 81-year-old former army commander and strong ally of the militant group Hezbollah, as the country's president, ending a more than two-year vacuum in the top post and a political crisis that brought state institutions perilously close to collapse.