Isla Smith's mother believes she survived thanks to a special bond with her identical twin after doctors said she was the "sickest baby in the hospital".
The youngster needed 47 pints of blood following complications to fix four major heart defects.
Isla also suffered internal bleeding and spent a week on an artificial heart and lung machine after her body went into "meltdown" following open heart surgery.
At just seven months old, she was so ill that doctors at a Glasgow hospital told her parents, Laura and James, from Lasswade, Edinburgh, that their daughter was just an hour from death.
Now the toddler has just celebrated her second birthday with twin Catherine, after battling countless infections, pneumonia and spending three weeks on a ventilator.
Mrs Smith, 33, said: "Without the doctors and surgeons at Yorkhill, Isla would not be here. They were amazing. But when they started to bring Isla round [in intensive care] she improved when Catherine was there.
"If Catherine made a sound, Isla would flinch and move about. Research has shown that an identical twin will heal 20% quicker if they are kept with their twin and I believe having Catherine there made a big difference."
She added: "Now we just love having them back together. It's exactly how it should be. Even the doctors said Isla was a miracle baby."
At one point Isla, had six drains removing fluids from her lungs, lines of medicine going into every vein in her tiny body, and her heart was so swollen surgeons had to leave her chest open for two days to give it space to work.
She was on so much morphine for so long that she had to be weaned off it and received so many blood products during her three months in hospital, that it would take both her parents more than 10 years to donate the same amount. At one point, supplies ran out in Glasgow and they were delivered from elsewhere in Scotland.
Mrs Smith said: "It was petrifying when the blood had to be couriered in as you just expect it to be available. Without it she would have died. This man in a helmet just came up to the ward and handed the nurses blood for our daughter. It was surreal."
The nightmare began when a scan 20 weeks into Laura's pregnancy showed Isla had tetralogy of fallots - four major heart defects, including a hole in the heart.
The twins were born by caesarean section at Edinburgh Royal Infirmary on December 21, 2011, weighing 4lb 2oz and 5lb 11oz respectively.
To begin with, Isla needed no medication but at seven months she needed open heart surgery at Yorkhill to correct the defects.
The operation was expected to take four hours but complications meant it took nine hours, as her heart was worse than initially thought. Over the next 24 hours Isla's heart became so swollen that the intensive care unit was transformed into a surgery to allow surgeons to open her chest to give her heart space to work.
After a week on the artificial heart and lung machine she started to improve. Mrs Smith said: "Her body took such a pounding. Everything in her body closed down. We are so glad to have our family intact and are so grateful."
The family has raised more than £3000 for Yorkhill Children's Charity to thank the medics who saved Isla.