LONDON — Sadiq Khan was elected Mayor of London on Friday, making him the most powerful Muslim politician in the Western world.

He won a resounding victory in the capital despite a hostile campaign by Prime Minister David Cameron’s Conservative Party, which attempted to link the South Londoner to terrorism and extremists.

Claims that Khan could not be trusted to protect London’s 8.5 million inhabitants backfired spectacularly, with senior Conservatives admitting that the divisive campaign drove voters away from the party.

Former Conservative chairwoman Sayeeda Warsi said her party’s strategy would cause lasting damage. “Our appalling dog whistle campaign for #LondonMayor2016 lost us the election, our reputation & credibility on issues of race and religion,” she wrote on Twitter as the results came in.

With most of the first-round votes counted, the Labour candidate had a lead of around 9 percent.

Khan, whose father became a bus driver when he moved to Britain from Pakistan, will command a $23 billion annual budget and oversee London’s policing, housing, and transport infrastructure.

The 45-year-old former human-rights lawyer was elected as a Member of Parliament for Tooting in South London just 11 years ago but he rose quickly through the Labour ranks.

In 2009, he became the first Muslim member of the British Cabinet, which required him to be sworn in by the Queen. He told the New Statesman: “The palace called me and said, ‘What type of Bible do you want to swear on?’ When I said the Quran, they said, ‘We haven’t got one.’ So I took one with me.”

Khan is a devout Muslim, who refrains from drinking alcohol, but he has often explained that his faith is just one facet of his character. “We all have multiple identities: I’m a Londoner, I’m British, I’m English, I’m of Asian origin, of Pakistani heritage, I’m a dad, I’m a husband, I’m a long-suffering Liverpool fan,” he said.

Zac Goldsmith, Khan’s Conservative opponent, started the race to replace Boris Johnson as a popular figure with a reputation for political independence who was best known for his advocacy of ecological issues.

His image has since been tarnished in the eyes of many Londoners who were disappointed by the tone of his campaign.

Shazia Awan, a former Conservative Party candidate, broke ranks ahead of Thursday’s vote to accuse her party of running a “racist” election campaign. She told The Daily Beast she was relieved by the result.

“I’ve voted Labour for the first time in my life and it is David Cameron’s and Zac Goldsmith’s vile racially charged rhetoric that has made me do so. We will not tolerate the vitriolic politics of hate,” she said. “We do not want the divisive campaign of Donald Trump in the U.K.”

Earlier this year, Members of Parliament debated whether Donald Trump should be prevented from visiting Britain under hate-speech laws after he proposed a ban on Muslims entering the United States.

If the presumptive Republican nominee where ever able to enforce his pledge, the Mayor of London, one of Washington’s closest allies, would be denied the right to attend summits in the U.S. or even travel to the United Nations headquarters in Manhattan.

Andrew Boff, the former leader of the Conservatives in the London Assembly, said his party would suffer lasting ramifications from the attempt to pit its diverse communities against one another. “I don’t think it was dog whistle politics because you can’t hear a dog whistle. Everybody could hear this. It was effectively saying that people of conservative religious views are not to be trusted and you shouldn’t share a platform with them. That’s outrageous,” he told the BBC. “It has done lasting damage.”

Khalid Mahmood, a fellow Muslim MP who has represented Birmingham for 15 years, told The Daily Beast he had been stunned by the decision to target Khan’s religion. “I was surprised to see some of the attacks which were personal to Sadiq,” he said. “The people of London have spoken and I think that should be a lesson to all politicians who try to go down that route because people are not prepared to take that.”

Before launching his own unlikely bid to become mayor, Khan developed a reputation as a fearsome campaigner. It was he who engineered Ed Miliband’s ill-fated victory over his brother David in the contest to be Labour leader in 2010.

He then oversaw two election campaigns in London where the party performed far better than it did in the rest of the country under Miliband’s leadership. He was considered an outsider to win Labour’s mayoral nomination, and when he did, Goldsmith was immediately installed as the favorite to win their head-to-head matchup.

If his political star continues to rise at this pace, we may be looking at a contender to become Britain’s first Muslim prime minister.