He will move from the post of education secretary, to be replaced by universities minister Michelle Donelan.
The prime minister was battling to remain in No 10 as his handling of the row over scandal-hit former deputy chief whip Chris Pincher became the latest issue to raise questions over his judgment.
It follows partygate, a confidence vote which saw 41% of his own MPs withdraw their support and two by-election defeats.
Sunak said: “The public rightly expect government to be conducted properly, competently and seriously.”
He added: “I believe these standards are worth fighting for and that is why I am resigning.”
Javid said the British people “expect integrity from their government” but voters now believed Johnson’s administration was neither competent nor “acting in the national interest”.
The twin resignations of Javid and Sunak mean Johnson’s position is now in the balance, but Cabinet ministers including Dominic Raab, Liz Truss, Michael Gove, Therese Coffey and Ben Wallace indicated they would be staying in the government.
However, Bim Afolami quit as Tory vice-chair live on TV, Theo Clarke and Andrew Murrison resigned as trade envoys and ministerial aides Jonathan Gullis, Saqib Bhatti, Nicola Richards and Virginia Crosbie left their roles.
The prime minister’s fate may ultimately lie with backbench MPs if the Tory 1922 Committee’s rules are changed to allow another confidence vote within 12 months.