Sadiq Khan, the son of Pakistani immigrants who won a landslide victory in this week’s London mayoral election, was sworn in on Saturday in a multifaith service at Southwark Cathedral, becoming the British capital’s first Muslim mayor.

Khan’s wide margin of victory was seen as a repudiation of the Islamophobic campaign waged by his main rival, the Conservative Party candidate Zac Goldsmith, whose own sister, Jemima, expressed regrets about it after her brother’s 14-point defeat was confirmed.

The 1.3 million votes Khan won as the Labour Party candidate gave him the largest personal mandate of any directly elected leader in British history. That achievement, and his rise from humble origins, won him praise from Britons online, even Conservatives like Sajid Javid, the business secretary, and Sayeeda Warsi, a former cabinet minister — who were both, like Khan, the children of Pakistani bus drivers.

Baroness Warsi, who is now in the House of Lords, also denounced the Goldsmith campaign for relying on barely concealed racist messages, like falsely implying that Khan could be linked to Islamic extremists.

Pakistanis watched from afar with pride, but also an awareness that the upwardly mobile trajectory of the Urdu-speaking lawyer’s career — which led him from subsidized housing to the House of Commons and then City Hall — would have been far less likely in his parents’ homeland.

As Hendrik Hertzberg, the New Yorker writer, observed, if Khan’s election were to be followed in November by a victory for Donald Trump, his complete ban on Muslims visiting the United States would make even London’s mayor persona non grata.

The warm glow on Saturday stood in contrast to a striking image from the night before, when the result was first announced. As Khan stepped to the microphone to speak, a minor party candidate for the extreme nationalist Britain First party turned his back.

In a brief speech after he signed the oath of office, Khan referred to the Goldsmith campaign’s failed effort to appeal to that sort of prejudice. “Fear doesn’t make us safer, it only makes us weaker,” he said, “and the politics of fear is simply not welcome in our city.”

In an interview with the political editor of Sky News, Faisal Islam, Khan said that it was not up to him to say if the Conservative Party’s leader, Prime Minister David Cameron, should apologize for having taken part in the effort to smear him. But, he said, “I think it’s for them to ask themselves the question, how is it that, in the most diverse, fantastic city in the world, they chose to have a negative, desperate, and divisive campaign?”