The drama highlighted the turbulent nature of politics in the nuclear-armed country that is vital to US hopes for ending the war in Afghanistan. The Americans need Pakistan's help in talks with the Taliban and are trying to persuade Islamabad to reopen war supply lines to Afghanistan.

Mr Ashraf was the second choice to replace Yousuf Raza Gilani who was dismissed by the Supreme Court earlier this week for refusing to initiate a corruption investigation against his boss, president Asif Ali Zardari.

The ruling Pakistan People's Party then nominated outgoing textile minister Makhdoom Shahabuddin, but he was hit on Thursday by an arrest warrant for his role in a drug import scandal. The warrant was issued by an anti-narcotics force run by the military, which wields political power and has staged three coups in Pakistan's short history.

The PPP and its coalition partners elected Mr Ashraf as prime minister by a vote of 211 to 89. Supporters thumped their hands on their desks in a show of support while PPP members in the balcony chanted "Long Live Bhutto" in homage to the party's founder, Zulfiqar Ali Bhutto.

Speaking to MPs after his election, Mr Ashraf said the economy, the power crisis and inflation were his main priorities. "Our country cannot afford politics of confrontation at this time," he said. The Gilani government, widely criticised as corrupt and inept, has done nothing to fix the country's problems. Mr Ashraf said he wanted to deal with the US on an equal footing. Speaking in English in an otherwise Urdu-language speech, he also said there would be no peace in Pakistan without peace in Afghanistan.

The government's term was scheduled to end in March 2013, but it is now expected to end sooner because of the pressures on the coalition.

Mr Ashraf, meanwhile, is expected to face the same demand from the Supreme Court - a panel of activist judges - to act on the corruption case against Mr Zardari. The case was initially heard by Swiss legal authorities in the 2000s and dates back to allegations that Mr Zardari laundered state money there in the decade before that.

Mr Ashraf was head of the water and power ministry for three years, an unpopular position in a country where daily blackouts in the steamy summer can be as long as 22 hours. Pakistanis ridiculed him for repeatedly claiming the power crisis would be over by "December" only to have conditions get worse the next summer. He has been accused of corruption relating to power projects. Mr Ashraf oversaw the import of short-term power stations, or "rental power" projects that cost the government millions of dollars but produced little energy. The policy earned him the nickname "Raja Rental" in the Pakistani media and opponents could be heard shouting the nickname in the vast parliament hall. He denies any wrongdoing, and supporters rallied to his defence.