London (CNN) Londoners will find out Friday if they have elected the first Muslim mayor of any major Western city, after an unusually bitter campaign in which race and religion have proven ugly flashpoints.

The race between Labour's Sadiq Khan, son of a bus driver, and Conservative candidate Zac Goldsmith, son of a billionaire, has seen the latter accused of peddling "vile race politics" in his campaign against his rival.

Khan, a 45-year-old lawyer and member of Parliament, is the London-born son of Pakistani immigrants, and a practicing Muslim in a city where his co-religionists comprise about 12% of the population.

Elections were held across the United Kingdom on Thursday, for mayoral positions, local council seats, and parliamentary and assembly seats in Scotland and Wales.

The Scottish National Party -- which campaigned for Scotland to leave the UK in 2014 -- won more Scottish Parliament seats than any other party, but failed to secure an outright majority. Labour plunged to third, behind the Conservatives -- a result that would have seemed unimaginable several years ago in the former Labour stronghold.

The SNP has tonight won an historic third term as Scotland's government. I pledge to be First Minister for all of Scotland. #SP16

Labour retained its place as the largest party in Wales — like Scotland, a traditionally left-leaning part of the country— but the pro-Brexit, anti-immigration UK Independence Party picked up its first seats there.

UKIP leader Nigel Farage tweeted that "UKIP now stands up for many traditional Labour voters abandoned by Mr. Corbyn's party" -- a reference to Jeremy Corbyn , who became Labour leader last year.

UKIP now stands up for many traditional Labour voters who have been abandoned by Mr. Corbyn's party.https://t.co/HitGK2kYA3 — Nigel Farage (@Nigel_Farage) May 6, 2016

The results of the London mayoral election are not expected until Friday.

The campaign took a particularly vicious turn when Goldsmith, trailing his rival in polls, penned a controversial column in Britain's Mail on Sunday newspaper on May 1.

Outrage over terrorist 'friends' article

This is not the @ZacGoldsmith I know.

Are we @Conservatives fighting 2 destroy Zac or fighting to win this election? pic.twitter.com/fzYBUDSjMG — Sayeeda Warsi (@SayeedaWarsi) May 1, 2016

Headlined "On Thursday, are we really going to hand the world's greatest city to a Labour Party that thinks terrorists are its friends?" the piece ran with an image of one of London's signature red double-decker buses that had been blown apart in the 2005 terror attacks in the British capital.

Zac Goldsmith, Conservative candidate for mayor

The attacks, carried out by Islamist extremists, left 52 people dead.

In the article, Goldsmith accused Khan and the leaders of the Labour Party of having, "whether intentionally or not, repeatedly legitimized those with extremist views."

The piece provoked outrage, and was seen as Islamophobic and unnecessarily divisive in a diverse city whose residents, Muslim and non-Muslim, live under the specter of the ISIS terror attacks that have struck Paris and Brussels in recent months.

The United Kingdom says the current threat level for international terrorism is at severe, meaning an attack is highly likely.

"Tomorrow we must defeat Goldsmith's vile race politics," wrote Maya Goodfellow, a writer for Labour-affiliated blog LabourList, in a comment that was retweeted by Labour MPs.

Tomorrow we must defeat Goldsmith's vile race politics | LabourList @MayaGoodfellow https://t.co/xIZjdpHKhK — Diane Abbott MP (@HackneyAbbott) May 5, 2016

Even members of Goldsmith's own party were critical.

Baroness Sayeeda Warsi, a Conservative parliamentarian and Muslim, tweeted: "This is not the Zac Goldsmith I know. Are we Conservatives fighting (to) destroy Zac or fighting to win this election?"

Labour's anti-Semitism scandal

The mayoral campaign has been taking place within a wider context of an anti-Semitism scandal gripping Britain's Labour Party, which has seen Labour MPs and councilors suspended after making or posting anti-Jewish remarks.

Critics have accused the left-wing party of being too accommodating of those with anti-Semitic and Islamist views, prompting the party's leader Jeremy Corbyn to set up an independent inquiry into the allegations.

One of those accused of having made anti-Semitic remarks was Ken Livingstone, the last Labour figure to serve as London mayor.

British Prime Minister David Cameron joined the fray, accusing Khan in Parliament of having shared a platform with an alleged ISIS supporter from his constituency on multiple occasions.

Khan tweeted in response to the accusations: "Disappointed PM has joined Zac Goldsmith's divisive, dog-whistling campaign. I've fought extremism all my life."

Khan: We need to do more

The candidate admitted in an interview with The Observer newspaper on Saturday that the anti-Semitism fight had probably hurt his prospects, and said his party needed to do more to confront the problem.

"There are too many examples in our party of people having these views, and action does not appear to have been taken quickly enough," he told the newspaper.

Some Labour figures had argued the scandal was the result of a political smear campaign against the party ahead of local elections.

Different social backgrounds

While Khan and Goldsmith are both MPs, the mayoral rivals hail from starkly different backgrounds.

Khan, along with his six brothers and sister, grew up in a three-bedroom public housing apartment. Eventually he studied law, became a university lecturer and the chairman of a civil liberties group, and became a member of Parliament in 2005.

Goldsmith, a former journalist, is the son of a billionaire businessman. He attended the elite Eton College and the Cambridge Centre for Sixth-form Studies, and was editor of The Ecologist magazine for nine years. He was elected to Parliament in 2010.

Photos: The many faces of Boris Johnson London Mayor Boris Johnson arrives at a Conservative Party election rally on May 5, 2015. As London elects a replacement for outgoing Mayor Boris Johnson, look back at some of his most photogenic moments. Hide Caption 1 of 14 Photos: The many faces of Boris Johnson London Mayor Boris Johnson knocks over 10-year-old Toki Sekiguchi during a touch rugby game in Tokyo on October 15, 2015. "I accidentally flattened a 10-year-old on TV unfortunately," Johnson said in a speech to British and American businessmen. "But he bounced back, he put it behind him. The smile returned rapidly to his face." Hide Caption 2 of 14 Photos: The many faces of Boris Johnson Johnson attends the protest of a third runway at London's Heathrow Airport on April 27, 2013. Hide Caption 3 of 14 Photos: The many faces of Boris Johnson Johnson speaks at the Conservative Party Conference in Manchester, England, on October 1, 2013. Hide Caption 4 of 14 Photos: The many faces of Boris Johnson Johnson falls while competing in a tug of war October 27, 2015, during the launch of London Poppy Day. Hide Caption 5 of 14 Photos: The many faces of Boris Johnson Johnson and model Kelly Brook launch a cycling festival in London on August 25, 2011. Hide Caption 6 of 14 Photos: The many faces of Boris Johnson Johnson plays wheelchair tennis to promote a tournament in London on November 24, 2014. Hide Caption 7 of 14 Photos: The many faces of Boris Johnson Johnson poses with members of a Carnival band in London on August 24, 2011. Hide Caption 8 of 14 Photos: The many faces of Boris Johnson Spiritual leader Acharya Swamishree Maharaj marks a bindi on Johnson's forehead during a visit to a new Hindu temple in London on May 28, 2014. Hide Caption 9 of 14 Photos: The many faces of Boris Johnson Johnson holds dance champion Camilla Dallerup at an event in London on July 1, 2010. Hide Caption 10 of 14 Photos: The many faces of Boris Johnson Johnson poses for a photograph to mark the start of a London Underground extension on November 23, 2015. Hide Caption 11 of 14 Photos: The many faces of Boris Johnson Johnson and actress Barbara Windsor play sitting volleyball after a Paralympics match in London on August 31, 2012. Hide Caption 12 of 14 Photos: The many faces of Boris Johnson Johnson takes part in an Olympics news conference on August 13, 2012. Hide Caption 13 of 14 Photos: The many faces of Boris Johnson Johnson eats in the Olympic Village in London on July 12, 2012. Hide Caption 14 of 14

Among the issues facing the new leader are affordable housing in a city increasingly drawing the superrich, aging infrastructure and transportation.

A rare Conservative mayor in the Labour-leaning British capital, Johnson is considered one of the country's most popular politicians. He is leading the campaign for Britain to leave to European Union at a referendum on June 23, running up against Cameron, who is in favor of the United Kingdom remaining.