Former cricket star Imran Khan has been elected prime minister of Pakistan in a vote at the country’s National Assembly.
His PTI party won the most seats in July’s elections – setting up Mr Khan to become PM with the help of small parties, more than two decades after he first entered politics.
He will be sworn in on Saturday.
Mr Khan, 65, will inherit a country with a mounting economic crisis and he has vowed to create a “new Pakistan”.
The charismatic sports star, who captained Pakistan to a World Cup victory in 1992, has long shed his celebrity playboy image and now styles himself as a pious, populist, anti-poverty reformer.
He ran on an anti-corruption platform that pledged to improve the lives of the country’s poor with an “Islamic welfare state”.
In Friday’s vote, Mr Khan was backed by 176 members. His opponent, Pakistan Muslim League-Nawaz (PML-N) president Shahbaz Sharif, received 96 votes.
Speaking after the results, the prime minister-elect vowed to bring about the “change that this nation was longing for”, according to local media.
He promised “strict accountability” for those who had “looted this country”.
“I did not climb on any dictator’s shoulders; I reached this place after struggling for 22 years.”
Opposition parties have claimed elements of last month’s elections were rigged. Despite this, they agreed to take their seats in the assembly.
In the lead-up to the election, Mr Khan was widely seen as the favoured candidate of the powerful military, which was accused of meddling against his rivals.
Applause and angry chants
Analysis by Secunder Kermani, BBC News, Islamabad
The announcement that parliament had chosen Imran Khan as the next prime minister was greeted by applause from his party, and angry chants from his rivals, the outgoing PML-N.
When it first became clear that the PTI had won the elections last month, Mr Khan addressed the nation in a conciliatory tone. Today he was more fiery.
He repeatedly rejected opposition claims that the vote was rigged and offered to investigate the allegations.
He challenged the opposition to hold a sit-in against him, telling them he would even provide them food and shipping containers to block roads.
Mr Khan faces real challenges, including a mounting economic crisis, but his supporters have high expectations of what he can deliver in terms of creating jobs, and improving healthcare and education. He promised to create a “new Pakistan”, now he will have to show the country what that looks like.
Before the election Mr Khan told the BBC that if he were to be elected, his initial focus would be on the economy. Pakistan’s currency, the rupee, has declined significantly in the last year. Inflation is on the rise and the trade deficit is widening.
Exports such as textiles have taken a hit from cheaper products by regional competitors, including China. Analysts say the new government may need to turn to the International Monetary Fund (IMF) for the country’s second bailout since 2013, which could complicate efforts to boost welfare.
After the 25 July election, Mr Khan also vowed to hold talks with India to seek a resolution to the dispute over the Kashmir region, a key flashpoint between the nuclear-armed countries.
He also called for “mutually beneficial” ties with the United States, despite being an outspoken critic of that country’s anti-terrorism measures in the region, such as drone strikes. President Donald Trump recently cut aid to Pakistan, accusing it of providing a “safe haven” to terrorists active in neighbouring Afghanistan.
Pakistan, a country with a population of nearly 200 million, has been ruled on and off by the military during its 71-year history.
Whether as a result of coups or corruption allegations, no prime minister in its history has ever successfully completed a term in office.
Three-time PM Nawaz Sharif was ousted from office in 2017 over corruption allegations.
He was jailed in the lead-up to the vote, and his brother, Shahbaz Sharif, led the PML-N party into the election.
After the election, three major opposition parties banded together to nominate Shahbaz Sharif as a joint candidate in a bid to thwart Mr Khan.
However, one of the parties – the PPP party of assassinated ex-Prime Minister Benazir Bhutto – is reported to have withdrawn its support for Mr Sharif in the run-up to the vote and abstained on Friday.