Pakistan on Tuesday elected businessman Mamnoon Hussain as its 12th president, state TV said, to replace deeply unpopular head of state Asif Ali Zardari, whose five-year term expires in September.
Lawmakers from both houses of the national parliament and four provincial assemblies voted in the two-man race for the largely ceremonial president of the nuclear-armed state.
In a sharp reminder of the challenges the country faces, dozens of heavily armed Taliban militants stormed a prison in the northwest overnight, escaping with more than 240 prisoners.
The economy has stagnated, a debilitating power crisis needs to be solved and US relations remain complicated by American drone attacks targeting Taliban and Al-Qaeda operatives.
Within minutes of the polls closing at 3pm, state media handed the vote to Hussain, based on unofficial results. The final tally is expected to be announced by the evening.
Hussain, a 73-year-old businessman and close ally of Prime Minister Nawaz Sharif in Pakistan's financial capital Karachi had been considered certain to replace Zardari.
Zardari's opposition Pakistan People's Party (PPP), which lost heavily in general elections in May, boycotted Tuesday's ballot over complaints that the vote was brought forward from August 6.
The only other candidate is retired Supreme Court judge Wajihuddin Ahmed, nominated by the Pakistan Tehreek-e-Insaf, the third largest party in parliament and led by cricket hero Imran Khan.
Hussain's loyalty to Sharif and low profile is expected to bolster the prime minister's authority and provide a stark contrast to Zardari, considered a sharp political operator behind the scenes.
A long-serving member of the ruling Pakistan Muslim League-N (PML-N) party, he briefly served as governor of the southern province Sindh under Sharif's last premiership in 1999.
On the eve of the election, Hussain told a PML-N meeting in the capital Islamabad that the office was a symbol of the federation of Pakistan and vowed to serve the country and its people.
Hussain made money in textiles and is a former president of the Karachi Chamber of Commerce and Industry (KCCI).
"He had no political affiliation until 1999 but his polite discourse and professional ability impressed Nawaz Sharif who made him governor of Sindh," current KCCI president Azhar Haroon said.
Supporters say Hussain's election could be important domestically by giving the south some stake in the federal administration, otherwise dominated by Punjab, Sharif's power base.
Constitutional amendments passed by the last PPP government mean that the presidency is again a ceremonial post, a status likely to be cemented by the fact that Hussain has little personal clout.
Sharif won a commanding general election victory in May, which marked the first time a Pakistani civilian government completed a full term in office and handed over to another at the ballot box.