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.

Army row

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 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.