The Prime Minister has promised to hold talks to renegotiate the terms of the UK’s membership and then put a new deal to the British people in a referendum after the next election.
While Mr Cameron has said he wants Britain to remain inside the EU, Mr Johnson said quitting would not be “fatal” for Britain.
Speaking to reporters at the Global Investment Conference, Mr Johnson said he remained “narrowly in favour” of staying inside the grouping of 27 member states and supported David Cameron’s policy of negotiating a new relationship for Britain in the EU.
But he added: “If that fails then yes, obviously, we should be ready to walk away,” he said. “We should be ready to leave.”
The public would welcome a British exit because people would feel they had won back control over their own lives from Brussels, the Mayor claimed.
“If we are honest, I think, democratically, it would be a shot in the arm because people would suddenly feel, yes, we are running our own destiny again, our politics is entirely independent, British electors can choose the people who are taking decisions that affect their lives.
“That would be a very important benefit.”
However, it would be essential to ensure British businesses did not suffer from losing trade in Europe.
Earlier, Mr Cameron had told the 300 conference delegates that he could negotiate a new relationship for Britain with Europe.
Mr Cameron attacked the “pessimists” who believed he would fail, in a direct rebuke to Tory grandees, such as Michael Portillo and Lord Lawson, who have called for the UK to withdraw from the EU.
“There are some pro European pessimists who say, you have to, in Europe, simply sign up to every single thing that anyone in the EU suggests.
You sign every treaty, you sign everything – there is no alternative.
“I think they are completely wrong,” Mr Cameron said.
“The second group of pessimists say there is no prospect of reforming the EU, you simply have to leave. I think they are wrong too.
“I think it is possible to change and reform this organisation and change and reform Britain’s relationship with it.”