Sadiq Khan, the Labour Party candidate for London mayor, would become the first Muslim mayor of a major Western capital if he wins Thursday’s election. (Hannah Mckay/Reuters)

As Londoners prepare to go to the polls Thursday, the race to succeed Boris Johnson as mayor has been dogged by allegations of negative campaigning not usually seen in London elections.

The main issue in the contest has been housing — in recent years, housing prices in the British capital have gone through the roof — but the campaign has turned increasingly bitter in recent weeks as it nears the finish line.

Sadiq Khan, the Labour Party front-runner, has been criticized for his links to alleged Muslim extremists, which in turn has triggered counteraccusations that his opponents are fanning the flames of divisiveness.

The Conservative Party’s Zac Goldsmith, Khan’s main rival, has said that his opponent has given “platforms and oxygen and cover and excuses” to extremists. Khan has shot back, accusing him of “Donald Trump-style” antics.

If Khan wins — polls show he has a sizable lead over Goldsmith — he would end eight years of Conservative rule in City Hall.

The Conservative Party’s Zac Goldsmith, center, accompanied by Mayor of London Boris Johnson, left, and British Prime Minister David Cameron, right, at a campaign event. (Hannah Mckay/Reuters)

He would also become the first Muslim mayor of a major Western capital at a time of heightened tensions over Islamist extremism after the terrorist attacks in San Bernardino, Calif., and in the European cities of Paris and Brussels.

Khan, 45, is the son of a Pakistani bus driver and seamstress who grew up in cramped government housing with his seven siblings. He trained as a lawyer and later became a Labour Party member of Parliament for the south London borough of Tooting, where he was raised.

Goldsmith, 41, comes from a wealthy, cosmopolitan family (he has Jewish ancestry and his nephews are Muslim) and studied at Eton College before he was expelled for possessing marijuana. A longtime environmentalist, he edited the Ecologist magazine before becoming a member of Parliament representing Richmond, a London suburb.

The mayoral race, along with a number of other British elections Thursday, has taken a back seat to the contentious debate over Britain’s membership in the European Union. President Obama recently caused a stir here when he said that if Britain leaves the E.U., it would be at the “back of the queue” for a trade deal with the United States.

It also does not feature big personalities such as former mayor Ken Livingstone, who was recently suspended from the ­Labour Party for controversial remarks, or Johnson, the flaxen-haired incumbent with the ­larger-than-life persona who is known across Britain simply as Boris.

But although the election may not feature flamboyant personalities, analysts say its tone has been, at times, nastier than those of past elections.

“In Britain, you get negative campaigning, of course, but it’s usually of a much more gentle variety,” said Tony Travers, a political expert at the London School of Economics.

David Cameron, the British prime minister and leader of the Conservative Party, ratcheted up the debate when he launched an attack on Khan. Cameron said Khan had appeared at nine events with Sulaiman Ghani, an imam from Khan’s constituency who Cameron said supports the Islamic State.

Ghani has condemned the Islamic State and demanded an apology. He said that he has fallen out with Khan over Khan’s support for gay marriage.

A former human rights lawyer, Khan said he has never tried to hide the fact that he has met with “unsavory characters.”

Khan, who is a fast-talking and pugnacious politician, called the tone of the contest a “Donald Trump approach to politics because it seeks to divide communities rather than unite them.”

He said in an interview that if he is elected, he hopes it will send a message that “the fact that you might be a son of immigrants, or [from] a poor background, or ethnic or religious minority, isn’t held against you, because you are respected for who you are and what you put in.”

He also added, half-jokingly, that if he becomes mayor, “I’ll need to rush to come to America before November because if Trump wins, I’ll be banned from coming.”

Goldsmith, a mild-mannered politician whose aides said he was not available for an interview, has insisted that he has run an “overwhelmingly positive” campaign and argued that it is legitimate to question Khan’s judgment.

It is unclear what impact any of the mudslinging will have on London voters, who have told pollsters that one of their top priorities is the city’s housing crisis.

The number of houses in London has lagged behind the population boom and sent prices skyward. A swath of the population, popularly referred to as “generation rent,” says it is nearly impossible to get a foothold on the property ladder.

“Finding affordable housing in London is very, very difficult,” said Cecilia Anim, president of the Royal College of Nursing, who attended a recent debate in east London.

“You can pay up to 1,600 pounds [$2,300] rent a month,” she said. “An average nurse doesn’t earn enough to pay that and so is forced to do extra duties.”

Khan told the audience that if he is elected, 50 percent of new homes would be “genuinely affordable” and that Londoners would get “first dibs” over investors in the Middle East and Asia.

Goldsmith said he would double the current rate of new homes to 50,000 a year and would “relentlessly pursue rogue landlords.”

Asad Jaman, who works in management at the East London Mosque, one of Britain’s largest, left the rally undecided about whom he would vote for.

Like the majority of Londoners, Jaman traditionally supports Labour, but he also thinks that Goldsmith could wield more influence when negotiating with a Conservative government.

But he said that if Londoners select a Muslim mayor, it would inspire people from other ethnic minorities to enter mainstream politics.

“It would give a similar message to when Barack Obama was elected,” he said.

Read more:

The petty, mean and deliciously rude ways British politicians insult one another

Zionism and Hitler? A guide to the wild scandal rocking Britain’s left.

London mayor candidate once challenged a far-right leader to duel with swords

Today's coverage from Post correspondents around the world