Sadiq Khan, the new Labour mayor of London, has launched an extraordinary attack on David Cameron and his defeated opponent, Zac Goldsmith, accusing them of trying to turn different ethnic communities against each other to stop him winning in the capital.

Writing in the Observer after becoming the most powerful Muslim politician in Europe, Khan says the prime minister and Goldsmith deployed tactics “straight out of the Donald Trump playbook” – a reference to the anti-Muslim campaign of the Republican hopeful in the US.

Khan wrested control of the capital from the Tories after eight years under Boris Johnson, in what turned out to be a comfortable win. He said he had hoped the campaign would focus on issues such as housing, transport and air pollution. “But David Cameron and Zac Goldsmith chose to set out to divide London’s communities in an attempt to win votes in some areas and suppress voters in other parts of the city,” he said.

“They used fear and innuendo to try to turn different ethnic and religious groups against each other – something straight out of the Donald Trump playbook. Londoners deserved better and I hope it’s something the Conservative party will never try to repeat.”

His remarks came as senior Tories, including Mohammed Amin, chair of the Conservative Muslim Forum, broke cover to criticise their own party’s campaign as divisive and deeply unpleasant.

Khan chose Southwark Cathedral for his signing-in as mayor, where he said he was determined to govern for all Londoners and “every single community”.

His savage remarks about Cameron will infuriate the prime minister and stoke tension between the two, who will have to work together on security and other issues in the months and years ahead.

What Labour can learn from my victory: we can’t ignore the things most voters want | Sadiq Khan Read more

During the campaign, run by Cameron’s election strategist Lynton Crosby, the Tories tried to paint Khan as a radical, suggesting he had questions to answer because he had shared platforms with extremists in the past and defended them in his time as a human rights lawyer.

Khan later said it was a matter for Cameron whether he wished to apologise for the content and tone of the Tory campaign, but vowed to work with the him in the interest of Londoners.

The defence secretary, Michael Fallon, who described Khan during the mayoral election campaign as a “Labour lackey who speaks alongside extremists”, repeatedly refused to say whether he was worried about Khan’s election and the safety of Londoners during an interview on Radio 4’s Today programme. Finally, under pressure from interviewer Sarah Montague, Fallon conceded that “London is safe with a Conservative government working with the new mayor of London”.

In his Observer article, Khan, whose team were not keen on Jeremy Corbyn attending Saturday’s ceremony, according to reports, also delivers a clear message to the Labour leader on how to win elections after a set of local, Scottish and Welsh results that left some Labour MPs questioning Corbyn’s future. Labour suffered disastrous losses in Scotland, where it slipped to third place behind Ruth Davidson’s Scottish Conservatives. In English local elections, however, the party avoided predicted losses in key strongholds in the south.

“I learnt a great deal throughout the course of the campaign – about myself, about London and about the importance of reaching out to all sections of society. But there are two lessons in particular,” Khan writes. “First, Labour only wins when we face outwards and focus on the issues that the people actually care about. And secondly, we will never be trusted to govern unless we reach out and engage with all voters – regardless of their background, where they live or where they work.

“Squabbles over internal party structures might be important for some in the party, but it is clear they mean little or nothing to the huge majority of voters. As tempting as it might be, we must always resist focusing in on ourselves and ignoring what people really want.”

Khan suggests Corbyn is failing to appeal to a wide enough electorate, including middle-class and disaffected Tory voters.

“Labour has to be a big tent that appeals to everyone – not just its own activists. Campaigns that deliberately turn their back on particular groups are doomed to fail.

“Just like in London, so-called natural Labour voters alone will never be enough to win a general election. We must be able to persuade people who previously voted Conservative that Labour can be trusted with the economy and security as well as improving public services and creating a fairer society.”

Khan, the Tooting MP, secured 57% of votes in the mayoral contest once second preferences were taken into account. Sources close to Corbyn said he was planning a public event with Khan in the next few days. The Labour leader is also expected to address his MPs at what could prove a difficult meeting of the parliamentary Labour party on Monday.