Parliamentarians in Nepal have elected a new prime minister after more than seven months of stalemate.
The deadlock was finally resolved when the Maoists, the largest single party, decided to withdraw their own candidate and to support Jhalanath Khanal, the chairman of a smaller allied party.
Nepal has been without a functioning government since June.
Many Nepalese are angry, saying issues including the economy and the peace process have been neglected.
"Jhalanath Khanal secured 368 of the 598 votes cast, giving him a majority," speaker Subash Chandra Nemwang told parliament.
It was the 17th time Nepalese MPs had voted to elect a new prime minister. Changes in the election process helped to clear the deadlock.
Jhalanath Khanal's victory came after a last-minute decision by the Maoist party to withdraw their own candidate - Pushpa Kamal Dahal, also known as Prachanda - from the race.
An hour before the vote was due, they announced they would support Mr Khanal, whose Communist Party of Nepal - Unified Marxist-Leninist (CPN-UML) is the third largest in the house.
Analysts say the Maoists made this decision because Mr Khanal was sympathetic to their views, and it was unlikely that they would have been able to gain enough support to lead a majority government themselves.
Nepal has had no prime minister after Madhav Kumar Nepal resigned in June, under pressure from the Maoists in a row over the control of the army and the integration of former fighters into regular forces.
Mr Nepal has been running a caretaker government ever since.
Mr Khanal, 60, is a veteran politician who was involved in the pro-democracy protests against the monarchy in 1990 and again in 2006.
A 2006 peace deal ended the war between the Maoists and the then royal government, in which more than 16,000 people were killed.
The Maoists won parliamentary elections in 2008 and the 239-year old monarchy was later abolished.
It is hoped that the new administration will be able to move forward on the two key issues that have held up the country's long-running peace process - deciding the future of more than 19,000 former Maoists fighters, and the completion of a new democratic constitution, says the BBC's Joanna Jolly in Kathmandu.
However, there are fears that if Nepal's new communist-led government does not work closely with the opposition Nepali Congress party, the divisions that have paralysed politics for the past few years will continue to block the country's development, our correspondent adds.