In a speech he said Britons, like Ukrainians, had the instinct “to choose freedom” and cited the 2016 vote to leave the EU as a “recent example”.
The comments have caused anger among politicians both in the UK and Europe.
Donald Tusk, the former president of the European Council, called the comments offensive.
Conservative peer Lord Barwell said voting in a referendum was not “in any way comparable with risking your life” in a war, while Liberal Democrat leader Sir Ed Davey said it was an “insult” to Ukrainians.
The row comes as the prime minister strongly urged China to condemn the Russian invasion in an interview with the Sunday Times. He suggested Beijing was having “second thoughts” about its neutral stance.
Mr Johnson likened the Ukrainians’ fight to Brexit in a speech to the Conservative Party’s spring conference in Blackpool on Saturday.
He said: “I know that it’s the instinct of the people of this country, like the people of Ukraine, to choose freedom, every time. I can give you a couple of famous recent examples.
“When the British people voted for Brexit in such large, large numbers, I don’t believe it was because they were remotely hostile to foreigners.
“It’s because they wanted to be free to do things differently and for this country to be able to run itself.
Mr Johnson also cited as an example British people choosing to get vaccinated against coronavirus because they “wanted to get on with their lives” and “were fed up with being told what to do by people like me”.
But his remarks, intended to rally the Tory faithful, attracted criticism from political figures in the UK and Europe.
Asked about Mr Johnson linking the plight of Ukraine to Brexit, Chancellor Rishi Sunak told the BBC’s Sunday Morning programme: “I don’t think the prime minister was making a direct comparison between these two things – clearly they’re not directly analogous.”
“He was making some general observations about people’s desire for freedom,” he added.
Mr Sunak said the prime minister had been galvanising global opinion to send a strong message to Vladimir Putin, and “that’s the thing we should be focused on”.
Shadow chancellor Rachel Reeves called for the prime minister to withdraw his comments and apologise.
She told the BBC: “The people of Ukraine, who are fighting for their lives – in any way to draw a parallel to voting to leave the European Union, it is shameless.”
She pointed out that Ukrainian President Volodymyr Zelensky wanted to join the EU – and that “he clearly sees no such parallel”.
Lord Barwell, who served as Theresa May’s chief of staff in No 10, said: “Apart from the bit where voting in a free and fair referendum isn’t in any way comparable with risking your life to defend your country against invasion, and the awkward fact the Ukrainians are fighting for the freedom to join the EU, this comparison is bang on.”
Ukraine applied for fast-track membership of the European Union last month, shortly after the Russian invasion.
Mr Zelensky said on Friday he had spoken to the head of the European Commission Ursula von der Leyen and expected progress to be made on its application in the coming months.
Others who criticised Mr Johnson’s comments included Conservative MP Tobias Ellwood, chair of the defence select committee, who tweeted: “Comparing the Ukrainian people’s fight against Putin’s tyranny to the British people voting for Brexit damages the standard of statecraft we were beginning to exhibit.”
The Liberal Democrat leader Sir Ed called the prime minister a “national embarrassment”, adding: “To compare a referendum to women and children fleeing Putin’s bombs is an insult to every Ukrainian. He is no Churchill: he is Basil Fawlty.”
SNP Westminster leader Ian Blackford said Mr Johnson’s comments were “crass and distasteful”.
Speak out, Johnson tells China
Meanwhile in his interview with the Times, Mr Johnson has urged China to join in the global condemnation of Vladimir Putin’s invasion.
He warned Beijing that supporting Russia was akin to choosing the wrong side in World War Two, describing it as a battle between good and evil.
Mr Johnson told the paper that he believed some in Xi Jinping’s administration were having “second thoughts” about the neutral stance adopted by Beijing.
It comes just a few days after the US warned China that it would face consequences if it helped Russia evade sanctions.
“As time goes on, and as the number of Russian atrocities mounts up, I think it becomes steadily more difficult and politically embarrassing for people either actively or passively to condone Putin’s invasion,” Mr Johnson said.
“There are considerable dilemmas now for people who thought they could sit this one out, who thought they could sit on the fence.”