Image caption Mr Ashraf faces a difficult job

Pakistan's ruling party candidate has been elected prime minister, three days after the Supreme Court forced former PM Yousuf Raza Gilani from office.

Raja Pervez Ashraf, who won 211 votes in the 342-seat house, was a last-minute choice after a judge ordered the arrest of the preferred candidate.

But he inherits a troubled relationship between the civilian government, the judiciary and the all-powerful army.

Mr Gilani's removal from office was seen as part of a long and bitter feud.

Observers say Pakistan can ill-afford its constitutional in-fighting - the country's economy is in crisis, as are relations with the US, and militants are waging a violent insurgency in tribal areas near the Afghan border.

Sleaze row

Analysis Raja Pervez Ashraf sported a broad smile as he crossed aisles to embrace members on the opposition benches. He exchanged pleasantries with the chief of the JUI-F party, Maulana Fazlur Rahman, who withdrew from the contest minutes earlier, setting the stage for a two-way split in the house. Many also predict another clash with the judiciary which wants a corruption case against President Zardari reopened in Switzerland, but which Mr Ashraf is unlikely to pursue. How soon the showdown comes is anybody's guess. But if the judges put him on a long leash, Mr Ashraf is likely to make a big push to improve the electricity situation in the country. This will not only wash away the stigma of his earlier failure, but may also win his party the next election.

Mr Ashraf emerged as the likely next PM after high drama on Thursday which saw a judge issue a warrant for the arrest of the previous candidate, Makhdoom Shahabuddin, as he was filing his nomination papers.

He received 211 votes out of 342 from members of parliament. There was only one other candidate standing against him for the post. Sardar Mehtab Ahmed Khan Abbasi from the PML-N party of opposition leader Nawaz Sharif received 89 votes.

General elections are due by early next year and correspondents say that Mr Ashraf's term is likely to be troubled and short.

As with many politicians in Pakistan, the new prime minister also faces controversy.

He has been dogged by allegations of corruption relating to power projects when he was water and power minister. He denies the charges.

He is also likely to face the same Supreme Court demand as Mr Gilani for the launch of a corruption inquiry into Mr Zardari.

It was Mr Gilani's refusal to do so that led to his conviction for contempt in April and his disqualification from public office two months later. He argued the president had immunity from prosecution.

Sacrificial lamb?

Raja Pervez Ashraf Born in 1950, Raja Pervez Ashraf comes from a land-owning political family with strong connections to Sindh province

He has been active in national politics since 1988 but lost repeated parliamentary elections until the 2002 and 2008 polls

Since 2008 he has served as both water and power minister and information technology minister

But his time as water and power minister was dogged by power cuts and controversy over a power generation scheme

He denies charges of kickbacks but investigations are ongoing Profile: Raja Pervez Ashraf

The charges against President Zardari date back to the 1990s when his late wife Benazir Bhutto was prime minister. They were accused of using Swiss bank accounts to launder bribe money.

President Zardari has always insisted the charges against him are politically motivated.

The BBC's Aleem Maqbool in Islamabad says Mr Ashraf is being seen as something of a sacrificial lamb.

The fact that he too has a corruption scandal hanging over him is for many irrelevant, our correspondent says - they see a judiciary that is now hell bent on bringing down President Zardari's Pakistan People's Party.

The PPP's main aim, correspondents say, is to see out its full five-year term, which would be a first for a civilian government in a country ruled by the military for more than half its history.

Some observers believe the PPP could benefit electorally if voters perceive it to have been persecuted by the judges and the powerful military.