LONDON — David Cameron, the British prime minister who called the Brexit referendum, says in a new memoir that Boris Johnson, Britain’s leader now, embraced withdrawing from the European Union only when he sensed it would be politically advantageous.

“He risked an outcome he didn’t believe in because it would help his political career,” Mr. Cameron, who stepped down in 2016 after voters surprisingly backed a withdrawal, writes in the memoir, “For the Record.”

After three years of relative silence from the former prime minister, the excerpts from his book read alternately as public apology — of sorts — and personal defense from a man who is still being blamed by many Britons for the political chaos the country now finds itself in.

Mr. Johnson became prime minister about two months ago and advocates leaving the European Union under any circumstances.