The government's chief law officer had made clear in a speech on Wednesday that he wanted to hold on to the post, and said after his dismissal that he was 'leaving the government at the prime minister's request'.
Cox, who spoke at the launch of Mr Johnson's bid for the Tory leadership last year, is understood to have fallen foul of the prime minister because of his insistence on speaking out independently in cabinet.
In a letter of resignation - which he made clear he had made at Mr Johnson's request - the outgoing attorney appeared to allude to this by referring to his efforts to deliver "candid and independent" advice to the PM and his predecessor Theresa May.
Known as parliament's highest-earning MP before his appointment to Ms May's cabinet in 2018, the barrister and QC won plaudits from Westminster-watchers for his deep baritone voice and his Rumpole of the Bailey-style rhetorical flourishes.
Boris Johnson's cabinet reshuffle: Who's in and who's out
Show all 17
He hit the headlines last September when he branded parliament a "disgrace" following the Supreme Court decision outlawing Mr Johnson's suspension of the Commons.
Standing at the despatch box, he launched a blistering attack on MPs for being "too cowardly" to hold an election, adding: "This parliament is dead."
In his letter to Mr Johnson, he recalled his role at his leadership launch, in an apparent reminder of the loyalty he had shown to the PM.
And he wrote: "I bluntly told the House of Commons in September that they risked incurring the wrath of the British people by continually frustrating the result of the referendum, and that a reckoning at the polls would come.
"It is very good news for our country and a source of great personal satisfaction to me that you have so emphatically proven those predictions to be correct."
Mr Cox, 59, has been MP for Torridge and West Devon since 2005.
Join our commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies
Join our commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies