The appointment came the day after video footage emerged of Mr Hancock kissing an aide in his ministerial office in a breach of coronavirus restrictions.
Images and video showed Mr Hancock in an embrace with aide Gina Coladangelo last month, and the former Health Secretary was facing increasing pressure to quit which came to a head on Saturday when he gave Boris Johnson his resignation.
In a letter to the Prime Minister, Mr Hancock said: "The last thing I would want is for my private life to distract attention from the single-minded focus that is leading us out of this crisis.
“I want to reiterate my apology for breaking the guidance, and apologise to my family and loved ones for putting them through this. I also need to be with my children at this time."
He said: "We owe it to people who have sacrificed so much in this pandemic to be honest when we have let them down as I have done by breaching the guidance."
He added: "I know people understand how hard it is to deal with the unknown, making the difficult trade-off between freedom, prosperity and health that we have faced."
In a video posted on Twitter, Mr Hancock said: "I understand the enormous sacrifices that everybody in this country has made, you have made. And those of us who make these rules have got to stick by them and that's why I've got to resign."
A statement from 10 Downing Street released around 90 minutes later said: "The Queen has been pleased to approve the appointment of the Rt Hon Sajid Javid MP as Secretary of State for Health and Social Care."
Mr Javid quit as Chancellor in February last year after he said Mr Johnson set conditions "any self-respecting minister" would reject during a Cabinet reshuffle.
At the time, the Prime Minister ordered Mr Javid to fire his closest aides and replace them with advisers chosen by Number 10 if he wanted to remain in post - conditions he said he was "unable to accept".