Londoners voted in Khan, 45, as the first Muslim mayor of a major Western capital city. He will take office in a metropolis where his fellow Muslims comprise about 12% of the population.
His victory followed an unusually bitter campaign against Conservative candidate Zac Goldsmith, the son of a billionaire, in which race and religion have proven ugly flashpoints.
The London-born son of Pakistani immigrants, Khan grew up with his six brothers and sister in a three-bedroom, public housing apartment. He studied law, became a university lecturer and the chairman of a civil liberties group, and was elected to Parliament in 2005.
Affordable housing in a city increasingly drawing the super-rich, aging infrastructure and transportation are top issues facing the new mayor.
Khan is replacing incumbent Boris Johnson, a colorful and popular figure who took office in 2008 and was a rare Conservative mayor in the Labour-leaning British capital.
Johnson is leading the campaign for Britain to leave the European Union at a referendum on June 23. He is clashing with Prime Minister David Cameron, who is in favor of the United Kingdom remaining.
Labour plunges in Scotland, UKIP gets first seats in Wales
The London race was one of several in the United Kingdom on Thursday. Voters also elected candidates 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.
In Wales -- like Scotland, a traditionally left-leaning part of the country -- Labour retained its place as the largest party. But the pro-Brexit, anti-immigration UK Independence Party (UKIP) 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.
Outrage over terrorist 'friends' article
In London, the mayoral campaign took a particularly vicious turn when Goldsmith, trailing his rival in polls, penned a controversial column May 1 in Britain's Mail on Sunday newspaper.
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.
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.
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?"
Goldsmith, a former journalist, 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.
Labour's anti-Semitism scandal
The mayoral campaign has been taking place amid an anti-Semitism scandal gripping Britain's Labour Party, which has seen Labour MPs and councilors suspended after making anti-Jewish remarks.
Critics have accused the left-wing party of being too accommodating of those with anti-Semitic and Islamist views, prompting Corbyn, the party's leader, 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.
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."
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.