Matt Hancock, the minister charged with fighting Britain’s biggest postwar health crisis, quit on Saturday night in the face of fierce criticism of his relationship with an adviser whom he put on the public payroll.

He will be replaced as health secretary by Sajid Javid, the former chancellor, who is making a comeback after his resignation in 2020 following an acrimonious power struggle.

During the course of Saturday support for Hancock leached away, with Tory MPs saying his position had become untenable, while cabinet ministers refused to back him publicly.

At just after 6pm, Downing Street confirmed that Hancock had resigned. The minister admitted in his resignation letter that he had let people down by not abiding by his own health guidelines.

On Friday Boris Johnson, prime minister, had seemed determined to hold on to Hancock, in spite of the health secretary admitting he had broken social distancing guidance by kissing his adviser Gina Coladangelo in his Whitehall office in May.

On Saturday evening it was announced that Coladangelo had also left her position as a non-executive director at the health department.

In his resignation letter, Hancock 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: “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.”

Johnson moved swiftly to replace Hancock with Javid, who quit in 2020 after Dominic Cummings, the former Downing Street adviser, tried to clip his wings by sacking all of the chancellor’s political advisers.

Johnson had not expected Javid to quit over the Number 10 power grab and the two men have remained on good terms.

Cummings tweeted on Saturday night that he had “tricked” Johnson into sacking his chancellor so that he could create a new economics team spanning No 10 and No 11 Downing St.

“Saj = bog standard = chasing headlines + failing = awful for NHS,” he tweeted, claiming that the new health secretary had been appointed by Carrie Symonds, Johnson’s wife.

Symonds used to work for Javid, who joins Rishi Sunak, Priti Patel and Kwasi Kwarteng in an increasingly diverse top cabinet team.

Javid will take on the role just as the country starts to emerge from the pandemic, but with many health challenges lying ahead, including a huge NHS backlog.

Hancock, who is married, apologised to his family for putting them through the ordeal of seeing his relationship on the front page of every national newspaper and said he wanted to spend time with his three children.

Senior Conservatives said there were no new revelations about his conduct that forced Hancock’s resignation, but Tory MPs were privately and publicly highly critical of his initial decision to cling to his job.

Duncan Baker, North Norfolk MP, told the Eastern Daily Press: “I will not in any shape condone this behaviour and I have in the strongest possible terms told the government what I think.” Esther McVey, a former minister, told GB News “if it would have been me I would have resigned”.

Johnson, in his reply to Hancock’s resignation, suggested he could make a comeback at a later stage. “You should be immensely proud of your service,” he said. “I believe your contribution to public service is far from over.”

The fallout of Hancock’s relationship with his adviser, whom he appointed to a £15,000 part-time job as a non-executive director at his department, threatened to dominate political debate in a crucial week for Johnson.

The Conservatives are hopeful of winning the Labour seat of Batley and Spen in a parliamentary by-election on Thursday, but opinion polls showed the public felt Hancock should quit.

Labour has claimed that Hancock’s conduct showed there was one rule for senior Tories and another for ordinary members of the public.

One senior Tory party official said: “It was inevitable. There was real anger in the party about breaking the Covid rules.”

Social distancing guidelines against close contact with a person from another household were lifted two weeks after Hancock was pictured on a CCTV camera in his own department building kissing Coladangelo, communications director at retail chain Oliver Bonas.

One of Hancock’s fellow MPs said: “I was out canvassing on Saturday morning and two separate people came up to me in the street to harangue me about Hancock. It had cut through.”

Hancock had been due to introduce legislation soon to strengthen significantly the powers of the secretary of state over the NHS, reversing key aspects of a controversial 2012 shake-up of the service that gave NHS England operational independence.

Under the proposed legislation, the health secretary would be given “enhanced powers of direction” over the NHS including a veto over some senior health service appointments and the authority to step in earlier over decisions about whether to close or downgrade a hospital, for example.

Hancock and Downing Street had wanted to tighten their grip over the service, to ensure that general election promises to expand nurse numbers by 50,000 by the end of the parliament and offer 50m more GP appointments were delivered.

Hancock had also been due to play a role in deciding who should become the next chief executive of NHS England when Sir Simon Stevens steps down at the end of next month.