Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

LONDON — London appears poised to become the first major Western city to elect a Muslim mayor after a bitter and bizarre campaign that has earned comparisons to the chaotic U.S. presidential race.

Opinion polls suggest that Sadiq Khan is the frontrunner in Thursday’s election to replace New York-born Boris Johnson and take charge of transportation and strategic planning in one of the world’s most diverse cities.

The moderate Muslim, who supports LGBT rights including gay marriage, is up to 20 percentage points ahead of main rival Zac Goldsmith, the son of a Jewish billionaire.

The contrast with Khan, who is the son of a bus driver from Pakistan and grew up with seven siblings in a three-bedroom government-subsidized apartment, resonates in an expensive city where rocketing rents and property values are squeezing out even middle-class workers.

Conservative mayoral candidate Zac Goldsmith campaigns in the Wimbledon area of London on Tuesday. FACUNDO ARRIZABALAGA / EPA

Yet the campaign has been overshadowed in recent days by accusations of anti-Semitism and racism including a spat over a left-wing former two-term mayor's claim that Hitler was a Zionist.

This mayoral election, featuring what a Financial Times newspaper op-ed called a “dismal brace of candidates,” has earned comparisons with the 2016 White House race and the outlandish influence of Donald Trump.

“The campaign has degenerated in a profoundly depressing way,” London reporter and blogger for The Guardian, Dave Hill, told NBC News.

Khan, from the opposition Labour Party, is among the majority of London’s 8.2 million inhabitants not classified as “white British.” According to the 2011 census, one in eight Londoners is a Muslim and 35 percent of the British capital’s residents were born overseas.

Related: How the Candidates for London Mayor Compare — ITV News

A lifelong environmentalist, Goldsmith edited the Ecologist magazine — owned by his uncle — before being elected to the House of Commons in 2010, representing the affluent riverside suburb of Richmond. He has promised to tackle delivery truck emissions and make London the world’s first genuinely “zero waste” city if elected.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Goldsmith, who is a member of Prime Minister David Cameron’s Conservative Party, has Jewish ancestors who fled fascism in Europe and his financier father was both a French member of the European Parliament and an anti-EU British lawmaker. Goldsmith is not a practicing Jew, and has Muslim nephews — his sister Jemima is divorced from Pakistani cricketer-turned—politician Imran Khan.

Sadiq Khan leads by 20 in London Mayoral race – https://t.co/ueF6JYhzg3 pic.twitter.com/vcGoRmfUQy — YouGov (@YouGov) April 21, 2016

Identity rarely features in British election campaigning but Goldsmith, with the support of Cameron, has for weeks focused on Khan's past career as a human-rights lawyer that included public appearances alongside radical Muslim speakers, accusing Khan of giving "platform, oxygen and cover" to extremists.

Khan admits that, prior to his political career, he sometimes shared platforms with people whose views he opposed. He has promised to be "the British Muslim who takes the fight to the extremists" and accused Goldsmith of running a "nasty, dog-whistling campaign."

Labour Party candidate for London Mayor Sadiq Khan (right) and his wife Saadiya pose after casting their votes on Thursday. JUSTIN TALLIS / AFP - Getty Images

The spat has left a sour taste in a city where authorities have foiled several Islamist terrorist plots since suicide bombers killed 52 people on the transit system in July 2005.

Four out of five Londoners say they are worried about another terrorist attack happening in the city, including more than one-third (37 percent) who are very worried, according to a ComRes/ITV News London poll. This compares to 67 percent who are worried about another global recession happening, and 57 percent who are worried about their personal security.

Conservative commentator Peter Oborne wrote last month that Goldsmith’s tactics of playing to those fears are “profoundly at odds with the British tradition” and “horribly reminiscent” of the Trump campaign.

Someone's not briefing Zac. Forgets London football clubs, tube stations, and then this cringe moment re Bollywood https://t.co/NhJtN3w8Am — Paul Brand (@PaulBrandITV) May 1, 2016

Last week the campaign took a further dive as Khan's Labour Party was accused of failing to stamp out anti-Semitism in its ranks amid controversy over comments by another lawmaker on her Facebook account saying that Israel should be moved to the United States.

Khan condemned the remark, but Labour colleague and former London mayor Ken Livingstone backed their Labour colleague and even stated that Hitler was "supporting Zionism" when he rose to power in the 1930s — a comment that generated an outcry.

Khan admits the fiasco has dented his campaign. "I accept that the comments that Ken Livingstone has made makes it more difficult for Londoners of Jewish faith to feel that the Labour Party is a place for them, and so I will carry on doing what I have always been doing, which is to speak for everyone," he said Sunday.

Hey @ZacGoldsmith. There’s no need to keep pointing at me & shouting ‘he’s a Muslim’. I put it on my own leaflets. pic.twitter.com/EGeRXlPWAa — Sadiq Khan MP (@SadiqKhan) April 11, 2016

The campaign has become “mired in rows about anti-Semitism and Islamophobia,” observes ITV News’ London political reporter Simon Harris — something that has exasperated Londoners seeking a solution to everyday problems such as a drastic lack of affordable places to live.

“It’s a symptom of wider politics,” said Betsy Dillner, director of housing campaign group, Generation Rent, whose social media campaign #ventyourrent has seen thousands of tenants share their horror stories about overpriced and substandard private apartments.

Labour mayoral candidate Sadiq Khan poses next to a campaign poster on March 29. NIKON CORPORA / Getty Images

“We are in a housing crisis,” she said. “In London there is a great opportunity for good jobs but if people can’t find a place to live the city will be a victim of its own success. We haven’t been building enough homes, we have let the market go crazy ... and we’re decimating our social housing stock.”

A report by bank UBS Global Real Estate, published in October, found London was less affordable than every major world city except Hong Kong for locals who want to own their home. Property prices have risen 40 percent since the start of 2013. According to England’s Land Registry, the average price of a home in London is almost $735,000 with annual increases averaging 9.6 percent

Zac Goldsmith’s hopes of becoming Mayor dealt blow as poll shows Labour on course to recapture City Hall https://t.co/5Vfe2N5n80 — Simon Harris (@simonharrisitv) April 5, 2016

Harris believes voters have been uninspired by a “lackluster” campaign from parties with “few distinctive policies on offer.”

“The mayor of London has the biggest personal mandate of any politician in England yet the 2016 contest for City Hall has failed to capture the imagination of the public,” he said. “Previous campaigns were dominated by big political personalities like the veteran left-winger Ken Livingstone and the current mayor Boris Johnson. By contrast, the two front-runners this time are far from household names.”

Mayor of London Boris Johnson cycles away after talking to journalists outside his home on Feb. 22. CHRIS RATCLIFFE / AFP - Getty Images, file

It’s a situation exacerbated by the mayor’s limited powers in comparison to other cities. In London, the 32 individual boroughs still run most services including schools, parks, public housing, licensing, garbage and street cleaning — leaving the mayor with a more strategic role and control of the city’s creaking Tube network.

Johnson has used his office to pursue headline-grabbing projects such as a new design for the city's iconic red buses, a controversial pedestrian "garden bridge" over the River Thames and a doomed campaign for a new airport in the river estuary.

By contrast, both Goldsmith and Khan are opposed to the expansion of London’s chronically congested Heathrow airport and there is little to separate them on plans to build more homes.

Hill believes that this election could mark a change in tone. “Ken Livingstone and Boris Johnston are both well-known, but mostly for saying rather stupid things. The mayor’s office in London doesn't have the same powers at it does in New York yet there is more to it than fiddling with bus fares and being a show-off.”

He added: “I'm personally quite pleased the Ken-Boris era is over — it's a chance for the institution of the mayoralty to reach maturity.”