LONDON — In a Europe struggling with a rise in Islamophobia, riven by debates about the flood of Syrian migrants and on edge over religious, ethnic and cultural disputes, London has elected its first Muslim mayor.
Sadiq Khan — a Labour Party leader, a former human rights lawyer and a son of a bus driver from Pakistan — was declared the winner after a protracted count that extended into Saturday. He will be the first Muslim to lead Britain’s capital.
The victory also makes him one of the most prominent Muslim politicians in the West.
London is hardly representative of Britain: About a quarter of its residents are foreign-born, and one-eighth are Muslim. And Mr. Khan is not the first Muslim to hold prominent office in Europe: Rotterdam, in the Netherlands, has had a Muslim mayor since 2009, and Sajid Javid is the British secretary of state for business.
Nonetheless, Mr. Khan, 45, won a striking victory after a campaigndominated by anxieties over religion and ethnicity. Britain has not sustained a large-scale terrorist attack since 2005, and its Muslim population, in contrast to France, is considered well integrated. But an estimated 800 people have left Britain to fight for or support the Islamic State. Dozens of assaults on British Muslims were reported after the Paris terrorist attacks in November.
The Conservative candidate, Zac Goldsmith, attacked Mr. Khan’s past advocacy for criminal defendants, including his opposition to the extradition of a man who was later convicted in the United States of supporting terrorism. Mr. Goldsmith said Mr. Khan had given “oxygen and cover” to extremists. When the Conservative prime minister, David Cameron, repeated those assertions in Parliament, he was accused of racism.
Mr. Khan defended his work as a human rights lawyer, and has said he hoped Donald J. Trump — the presumptive Republican presidential candidate who has called for barring Muslims from entering the United States — “loses badly.”
Mr. Khan’s victory was also his party’s biggest boost in a series of elections on Thursday in which Labour further lost its grip on Scotland, once a stronghold, and clung, in some cases just barely, to seats in England and Wales.
Mr. Khan won with 56.8 percent of the vote, versus 43.2 percent for Mr. Goldsmith, according to London’s election body. The results were not final until Saturday morning because in London’s electoral system voters are allowed a first and second preference, and Mr. Khan did not win an outright majority in the first round.
In his acceptance speech, Mr. Khan said that the mayoral election “was not without controversy” and added that he was “proud that London has today chosen hope over fear and unity over division.”
“I hope that we will never be offered such a stark choice again. Fear does not make us safer, it only makes us weaker and the politics of fear is simply not welcome in our city.”
Mr. Khan’s campaign focused on bread-and-butter issues like the cost of housing and transportation. He drew strong support from labor unions and kept a careful distance from his party’s leader, Jeremy Corbyn, a socialist who has an ardent base among young voters but faces heavy resistance among fellow Labour lawmakers.
Mr. Khan argued that, as an observant Muslim, he was well placed to tackle extremism. “I’m a Londoner, I’m European, I’m British, I’m English, I’m of Islamic faith, of Asian origin, of Pakistani heritage, a dad, a husband,” he said in a recent interview with The New York Times.
The fifth of eight children, Mr. Khan was born in Tooting, South London, to recent immigrants from Pakistan, and grew up in a public-housing project. His father drove a bus, and his mother was a seamstress.
Elected to Parliament in 2005, Mr. Khan was appointed a junior minister for communities in 2008, and minister for transport in 2009 under the last Labour prime minister, Gordon Brown. Although he was not one of the highest-ranking ministers, he became the first Muslim to attend cabinet meetings regularly and was admitted to the Privy Council, a largely ceremonial body in which induction normally requires taking an oath to the queen.
“The palace called me and said, ‘What type of Bible do you want to swear on?’ ” Mr. Khan told the magazine The New Statesman. “When I said the Quran, they said, ‘We haven’t got one.’ So I took one with me.”
As London’s mayor, he will have significant power over transportation and planning — as well as responsibilities for the police, civil defense and fire services — in a city with an acute shortage of affordable homes and a creaking, overcrowded mass transit network.
Mr. Khan will succeed Boris Johnson, a Conservative who has held the post since 2008 and is a leading figure in the campaign for Britain’s departure from the European Union. That vote will take place on June 23. Mr. Johnson is seen as a possible successor to Mr. Cameron as leader of the Conservatives, particularly if Britain votes to leave; Mr. Cameron is campaigning for Britain to remain.
Within Britain, the news of the collapse of the Labour Party in Scotland was almost as big as Mr. Khan’s victory.
The Scottish National Party won its third straight victory in the Scottish Parliament — a triumph that its leader, Nicola Sturgeon, called historic, even though the party narrowly lost its majority. The Labour Party fell to a humiliating third place, behind the Conservatives, who won seats in part by appealing to Scots opposed to independence. Scots rejected independence in a 2014 referendum, but there is speculation that a new referendum could be called, particularly if Britain leaves the European Union.
The S.N.P. won 63 seats, down from 69 and two short of the 65 required for a majority in the 129-seat Parliament, but it was far ahead of its rivals. Ms. Sturgeon said she planned to lead a minority government rather than seeking a coalition with smaller parties. The Conservatives captured 31 seats, and Labour 24.
“The Labour Party have completely lost touch with the hard-working people they’re supposed to represent,” Mr. Cameron, the prime minister, said.
In Wales, Labour remained the biggest party, though the U.K. Independence Party, which favors leaving the European Union, entered the Welsh Assembly for the first time, winning seven seats.
In England, Labour won two by-elections to the British Parliament, and a Labour mayor, Joe Anderson, won a second term in Liverpool. Labour also kept control of local councils in crucial English communities like Crawley, Southampton, Norwich and Hastings, where the party had been thought vulnerable.
Nonetheless, Mr. Corbyn’s troubles have taken the focus from the Conservatives, who are deeply divided over the June 23 referendum on European Union membership.
As for Mr. Corbyn, he said that Labour had defied its critics and “hung on” in England, though he conceded that there was “a lot of building to do in Scotland.”
This story was originally published here