One of the UK surgeons who successfully separated two-year-old conjoined twins in a highly complex operation, recently revealed he almost didn’t become a doctor after flunking out of medical school.

David Dunaway, 63, co-led the team that separated Pakistani toddlers Safa and Marwa Ullah at London’s Great Ormond Street Hospital — after nearly giving up on his dream of becoming a surgeon.

“I didn’t really put the work in,” Dunaway told The Sunday Post, explaining how he failed his first-year exams at the University College London medical school.

After flunking out, Dunaway said he worked for the Eveready Battery Company.

But watching all of his former classmates get their degrees reignited his determination to become a doctor.

He graduated with a degree in dentistry in 1980 and one in medicine at Manchester University in 1989, before starting his surgical training.

“It’s a good lesson in how, if you persevere, you can get things back on track,” he said.

Now, Dunaway performs complex head surgeries at the London children’s hospital, where he usually works 15-hour days.

The operation to separate the twin girls — who were born with a condition known as “craniopagus,” in which their skulls and parts of their brains were intertwined — took 55 hours and involved more than 100 medical staff.

The surgery took place five months ago, and the girls were discharged July 1.

They are currently staying in London with their mother Zainab Bibi, 34, and their grandfather Mohammad Sadat, according to the UK Times. Their father died before they were born.