The leader of Nepal's largest political party, Sushil Koirala, has been elected prime minister, promising to draft a new constitution within a year.
The Nepali Congress president, who was the only candidate, secured 405 of 553 MPs' votes, after the Communist Party of Nepal (UML) agreed to back him.
There has been political deadlock since November, when no party won a majority in Constituent Assembly elections.
Attempts to agree a new constitution have been dogged by years of wrangling.
Mr Koirala, 75, must now form a coalition. He will be the sixth head of government since the country became a republic in 2008, following a peace deal with Maoist rebels in 2006.
The Maoists won most seats in elections that followed the peace accord, but the government collapsed in 2012 after politicians failed to meet a deadline to agree on a constitution.
The Maoists were trounced in the November 2013 polls, coming third behind the Nepali Congress and the UML,
Mr Koirala's election comes after a deal agreed over the weekend between the two largest parties, which combined have just short of a two-thirds majority in the 601-member assembly.
BBC Nepali's Sanjaya Dhakal in Kathmandu says Mr Koirala is likely to have the support of some smaller parties, independents and other members in the new assembly, giving him on paper the numbers he needs to write a new constitution.
Whether he succeeds where so many others have failed will largely rest on how durable his alliance with the UML is, our correspondent cautions.
The new prime minister takes over from Chief Justice Khilraj Regmi, who has led a caretaker government since March last year.
Mr Koirala is descended from a line of politicians and activists who have long controlled the Nepali Congress, and is the fourth member of his family to become prime minister.
He was jailed for three years in his 30s for his involvement in the hijacking of a plane in India, which was known to be carrying cash that his relatives wanted to use to fund their party.