Myanmar's Parliament, in a vote broadcast live on television, has elected the country's first civilian president in decades - Mr Htin Kyaw, 69, an old friend and loyalist of National League for Democracy (NLD) leader Aung San Suu Kyi.
The military's nominee, retired general Myint Swe, was elected first vice-president, and the ruling NLD's second nominee, Mr Henry Van Thio, was voted in as second vice-president.
Mr Htin Kyaw got 360 of the total 652 votes in a joint session of the Upper and Lower Houses yesterday morning.
"Today's result is a triumph for Daw Aung San Suu Kyi," Mr Htin Kyaw told reporters as he left Parliament after the vote.
He is due to nominate a Cabinet next week and will take power on April 1, becoming the first elected president without an army background since Mahn Win Maung in 1962. He will take over from the mild-mannered retired general Thein Sein, 70, who was essentially handpicked for office in 2011 by retired military strongman Senior General Than Shwe.
First vice-president Myint Swe, 64, the outgoing chief minister of Yangon, is seen as an old-guard hardliner and is still on a US sanctions list. He received 213 votes, which would have included the military's 166 appointed seats - 25 per cent of Parliament.
Commenting on Mr Myint Swe's nomination last Friday, US State Department spokesman John Kirby said the US had "made its concerns known about this individual and this process, quite frankly, and we'll monitor it going forward''.
Second vice-president Henry Van Thio, 58, a little-known ethnic Chin Christian and an NLD MP in the Upper House, was elected with 79 votes.
Ms Suu Kyi, 70, cannot be president because of a clause in the junta-era Constitution that bars anyone with foreign relatives from the post; her two sons are British citizens. But she has said she will be "above" the president, indicating Mr Htin Kyaw will be her proxy.
She told NLD MPs last Thursday after his nomination that he had been chosen on three criteria - loyalty, discipline and qualifications.
Mr Htin Kyaw, low-profile and scholarly, is the son of noted writer Min Thu Wun, who was close to the late Myanmar diplomat U Thant, the first Asian secretary-general of the United Nations in the 1960s.
The president-elect has a master's degree in economics from Rangoon University and studied computer science in London and, briefly, management in the US while working for 12 years in the foreign affairs ministry.
During Ms Suu Kyi's 15-odd years of detention, he was one of the few allowed to see her. During a short period of freedom for her in 2000, he was jailed for four months for trying to help Ms Suu Kyi take a train out of Yangon in breach of the junta's travel restrictions.
Mr Htin Kyaw is also on the executive committee of the Daw Khin Kyi Foundation, named after Ms Suu Kyi's mother, which does human development work.
A couple of hours after the vote, Indian Prime Minister Narendra Modi tweeted: "Congratulations and best wishes to U Htin Kyaw on being elected president of Myanmar! Will work together to strengthen India-Myanmar ties."