Nepal has elected its fourth prime minister in four years, with the Maoist party's Baburam Bhattarai beating rival Ram Chandra Poudel in an MPs' vote.
Mr Bhattarai got 340 votes to the Nepali Congress party candidate's 235, thanks to the support of smaller parties based in the country's south.
He vowed to complete the peace process after 10 years of civil war and reach agreement on a new constitution.
His predecessor, Jhalanath Khanal, was in post less than seven months.
Mr Khanal, who represented the Unified Marxist Leninist party, resigned earlier this month, unable to forge a consensus.
One of the key sticking points in the peace plan has been the proposed integration of 19,000 former Maoist rebel fighters into the army, with military leaders and the Nepali Congress resisting the move.
The rebels, represented by Mr Bhattarai's party, fought a decade-long guerrilla campaign against the former monarchy until joining the United Nations-supervised peace process in 2006.
The monarchy was eventually removed from power in 2008 but more than 16,000 people had died in the civil war.
Confusions surrounding the new government are over but challenges remain, says the BBC's Surendra Phuyal, in Kathmandu.
In order to get the peace and constitution-making processes on track, Mr Bhattarai will need support from the opposition parties and his party hard-liners, our correspondent says. Otherwise, the peace process could drag on and on.
Mr Bhattarai, 57, faces the immediate challenge of agreeing the first draft of the new constitution before August 31, the expiry date of the constituent assembly.
There has been political deadlock on the issue since the parliament's election, with the Maoists as the largest party, in 2008.
However, Mr Bhattarai vowed to "prove nay-sayers wrong", reported AFP news agency.
"The country's future is very bright and we can accomplish the task of constitution-drafting and complete the peace process," the agency quoted him as saying.