Mr. Khan’s election would be a boost for the Labour Party at a time when Prime Minister David Cameron’s Conservatives are deeply divided on Europe. It would also probably strengthen the position of Labour’s left-wing leader, Jeremy Corbyn, who is at odds with many of his own lawmakers, and whose leadership has been embroiled in a dispute about anti-Semitism in party ranks.

But the main policy battles being fought on the streets of London relate to the problems confronting a city that has an acute shortage of affordable housing and a creaking and overcrowded mass transit network. Mr. Khan’s closest rival is Zac Goldsmith, the Conservative candidate, who says he wants to make London “the greenest city in the world.”

The two have battled over issues like transportation and how to build more homes to relieve London’s sky-high real estate and rental costs. Mr. Khan points to the fact that the average rent in London is equivalent to 55 pounds, or about $80, a night — the price of a decent hotel in many European capitals. And Mr. Goldsmith has said the overcrowded conditions endured by London commuters “would be illegal for chickens, pigs and cattle.”

Appropriately, perhaps, for a globalized city that accommodates the extremes of wealth, Mr. Khan and Mr. Goldsmith are living examples of London’s diversity.

Mr. Goldsmith, 41, a son of the tycoon Sir James Goldsmith, inherited a fortune and was educated at Eton College, Britain’s most exclusive school. He edited the magazine The Ecologist, founded by his uncle, and was elected to Parliament in 2010.