LONDON—Former Chancellor Rishi Sunak, who warned that Liz Truss ’ economic plans for Britain were a “fairy tale,” won the contest to succeed her as prime minister on Monday, taking over the world’s sixth-biggest economy at a time of deep financial and political turbulence.

Mr. Sunak will formally enter Downing Street after his only remaining rival for the job, former defense minister Penny Mordaunt, said on Twitter she would drop out of the contest. “Rishi has my full support,” she wrote.

Mr. Sunak’s rise to the top job in Britain marks a historic moment. The grandson of Indian immigrants to Britain, the 42-year-old will be the U.K.’s first person of color and the first Hindu to lead the country. But his success will be determined by how well he manages the growing challenges to Britain’s economy as high inflation and a looming recession create a sense of growing despair.

The former hedge-fund manager arrives with a mandate to bring calm to the ruling Conservative Party following a period of unparalleled chaos that will see the country run by three prime ministers in seven weeks—a first for the U.K. On Sunday night, his main rival for the job, the colorful but controversial former leader Boris Johnson, pulled out of the leadership race, citing the fact that he couldn’t unite the party.

Mr. Sunak takes over from Ms. Truss, who became the shortest-serving prime minister in British history after her flagship economic program to stimulate the economy with tax cuts during rising inflation was rejected by investors, causing the pound to sink to a record low and the Bank of England to intervene in bond markets to stabilize the price of U.K. government debt.

On Monday, financial markets reacted positively to Mr. Sunak’s victory. Yields on government debt fell as investors bet that Mr. Sunak, an experienced treasury official, will oversee cuts to public spending to shore up the nation’s finances.

The decision caps Mr. Sunak’s second attempt to secure his place as prime minister in months. He campaigned over the summer to become British leader but lost to Ms. Truss. During the campaign Mr. Sunak criticized Ms. Truss’s plan to borrow funds to immediately cut taxes. He said Britain’s high inflation, which is currently at 10.1%, needed to be tackled first before any taxes were cut.

“Liz’s plans are promising the Earth to everybody. I don’t think you can have your cake and eat it,” he said in August.

Mr. Sunak lost, but his arguments later won the day. Ms. Truss was forced to roll back her experiment to use unfunded tax cuts to spur economic growth.

While Mr. Sunak’s rise will placate markets for now, his government will face tough and unpopular decisions on spending. The U.K. Treasury is expected to outline plans on Oct. 31 to cut spending and potentially raise some taxes to fill an estimated 40 billion pounds, equivalent to $45 billion, deficit in the public finances. “The choice the party makes now will decide whether the next generation of British people will have more opportunities than the last,” Mr. Sunak said on Sunday.

Former Prime Minister Boris Johnson on Saturday, after flying back from a vacation in the Dominican Republic to canvass lawmakers.

Photo: Gareth Fuller/Zuma Press

His fiscal caution is likely to ease pressure on the Bank of England to raise its key interest rate sharply from 2.25%. Market expectations for the peak in the BOE’s interest rate next year fell to 5% from 6% in the days after Ms. Truss’s economic plan was axed.

The broader outlook, however, is grim. Mr. Sunak will likely face a winter of discontent as inflation, fueled by rising energy costs from the war in Ukraine, increases faster than wages, and a recession takes hold that economists think could last a year. The early stages of his tenure are likely to be punctuated by worker strikes and questions about whether electricity blackouts will be needed as Russia restricts gas exports to Europe.

In contrast to most other rich countries, the U.K.’s economy has yet to return to its prepandemic size. The U.K. economy grew very slightly in the three months through June, leaving it 0.2% smaller than in the final quarter of 2019, the last before the Covid-19 virus began to spread.

“The heightened political and economic uncertainty has caused business activity to fall at a rate not seen since the global financial crisis in 2009 if pandemic lockdown months are excluded,” said Chris Williamson, chief business economist at S&P Global Market Intelligence.

Mr. Sunak also faces another potentially more intractable challenge: uniting a party that has been at war with itself for years. The Conservative Party is at a record low in the polls against the opposition Labour Party. A recent poll by Opinium has 23% of Britons voting for the Conservatives versus 50% for Labour. Pollsters think the scale of that deficit, combined with the fact that the Tories will seek a record fifth term in office at the next election in 2024, is potentially insurmountable.

Mr. Sunak, who isn’t a famed political operator, must find a way of bringing together lawmakers who have polar opposite views on the direction that the U.K. economy should take. In the wake of the U.K.’s departure from the European Union, conservative lawmakers are split between embracing low regulation, a smaller government, and free trade, or protectionism and more state intervention as an aging population puts more strain on public services.

Mr. Sunak has previously campaigned on both fiscal conservatism, tight immigration restrictions and support for tackling climate change. His foreign policy outlook is less well defined. While he has expressed support for helping Ukraine fight off Russia’s invasion, he may have to cut military spending to bring finances under control. Mr. Sunak is a euroskeptic—having supported the vote to leave the European Union in 2016—but is seen as more conciliatory toward Europe than either Ms. Truss or Mr. Johnson.

Mr. Sunak represents an unusual mix of both continuity and newness at the top of British politics. He grew up in Southern England to parents of Indian origin, his father was a doctor and his mother ran a pharmacy. Mr. Sunak attended Winchester—an elite private school that has produced several British prime ministers—before attending the University of Oxford, then finding a job at Goldman Sachs. He married Akshata Murty, the daughter of an Indian billionaire businessman. The pair met while Mr. Sunak was studying for an M.B.A. at Stanford. He co-founded a hedge fund called Theleme Partners.

As the wealthiest member of the House of Commons, Mr. Sunak could find himself in the uncomfortable position of explaining support for spending cuts that could make life harder for the working classes. Backers say he will argue that sound finances will allow Britain’s economy to improve competitiveness to create broader prosperity down the road.

In 2015, Mr. Sunak was elected to parliament in Yorkshire, a northern English and mostly white agricultural district. Mr. Sunak took his parliamentary oath to the monarch on the Hindu scripture, The Bhagavad Gita, and had to explain to many of his farming constituents that he didn’t eat beef. But he quickly proved popular and moved to a Yorkshire manor.

Mr. Sunak’s star rose quickly in the Conservative Party. He came out in favor of Brexit, which he argued could allow Britain to become more internationally competitive outside the EU. The move went against the prime minister at the time, David Cameron, but put him in good stead with Mr. Johnson, who identified Mr. Sunak as a rising star. In 2019, he was given a senior role at the Treasury and placed his wealth in a blind trust to avoid allegations of impropriety. A year later he was made chancellor of the exchequer.

It was during the 2020 Covid-19 pandemic that Mr. Sunak came to the nation’s attention as he set up a job-protection program in a matter of days. The decision to have the government pay a percentage of people’s wages while they were unable to work during lockdown was well-received.

The former financier proved a good foil to the larger-than-life Mr. Johnson. Unlike Mr. Johnson, Mr. Sunak brought attention to detail. People who have worked with him say that he assiduously reads briefing notes and cross examines civil servants. During the pandemic, he repeatedly questioned the need for lockdowns. Mr. Sunak also has a nerdy side. The Star Wars fan once surprised a group of school children by telling them he has a “coke problem.” He then went on a minute-long monologue about his favorite type of Coca-Cola, which is made from cane sugar in Mexico.

By last summer, however, Mr. Sunak and Mr. Johnson were at odds. Mr. Sunak had successfully lobbied for taxes to rise to help pay for Britain’s struggling nationalized healthcare system. But many in Tory ranks questioned the fact that the tax burden was at its highest level in 70 years. Mr. Johnson meanwhile became embroiled in a “partygate scandal” where he was fined by police for attending his own birthday party in Downing Street during a Covid-19 lockdown. Mr. Sunak was fined for attending too.

Mr. Sunak was caught up in a scandal of his own. His wife Ms. Murty this year had to change her tax arrangements after admitting she benefited from tax rules that allowed her to pay no U.K. tax on her worldwide income. She says she changed that status and now pays U.K. tax on that worldwide income. The debacle made some Tory lawmakers question whether Mr. Sunak was too wealthy to connect with the party’s blue-collar voters.

But as more scandals washed over Mr. Johnson, Mr. Sunak moved to oust him. Last July he announced his resignation, which triggered an avalanche of further resignations making Mr. Johnson’s position untenable. Within days a polished website “Ready4Rishi” was online.

Mr. Sunak’s apparent eagerness to turf out Mr. Johnson soon played against him. In the ensuing leadership contest, Mr. Sunak racked up the biggest support from lawmakers but failed to convince the Conservative Party’s 170,000 members.

This time around, after Ms. Truss quit, many key lawmakers were quick to announce their support for Mr. Sunak and prevent another vote among party members.

Write to Max Colchester at max.colchester@wsj.com and Paul Hannon at paul.hannon@wsj.com