Mr Khan, Labour MP for Tooting and a former government minister, succeeds Boris Johnson to become the capital’s first Muslim mayor.
He had been cautious about the result, which he said could have been affected by the recent row over anti-Semitism in the Labour party.
During the campaign, Mr Khan was heavily criticised by Mr Goldsmith for his alleged links to Islamist ‘extremists’, accusations David Cameron repeated in the Commons.
This strategy was attacked today by Andrew Boff, Tory leader on the Greater London Assembly, who said: “I was supportive of the whole campaign apart from one element and that one was where it seemed to attribute radical tendencies to people of orthodox religious views.
“I think that is a complete misunderstanding of the patchwork of faiths there are in London, and has the potential to alienate people and say that people who do have orthodox religious views, conservative religious views, are for some reason not welcome and won’t be listened to.”
Labour leader Jeremy Corbyn said the Conservatives had run a “vile” campaign and had tried to “smear” Mr Khan, adding: “So many people are just revolted by what was said about Sadiq. Yesterday they came out and voted for us.”
Mr Johnson thanked the capital for his eight years in office as he sent his final messages from the official London Mayor Twitter account. He tweeted: “It’s time to sign off from City Hall – it’s been the most amazing privilege to be your mayor.”
In England’s council elections, Labour fared better than many commentators had expected, but did not do as well as opposition parties need to at this stage of the electoral cycle if they hope to win a general election in four years’ time.
The party was trounced in elections to the Scottish Parliament, where the SNP won a third term in power, albeit without a majority.
Labour was forced into third place behind the Conservatives, but won a fifth term in office in Wales.