Dr Fadi al-Kharti, who was at Deir al-Balah hospital when she was rushed in, said: "Her body was brought in after an Israeli shelling at 3:00 am on Friday.
"We tried to revive her but she had died on the way to hospital."
Doctors realised the baby was still alive when 'we noticed movement in her stomach'.
The doctor said: "We estimated she was about 36 weeks pregnant."
Medics performed an emergency Caesarean section and saved the baby.
The baby's grandmother, 43-year-old Mirfat Qanan, said it was a tragedy to lose her daughter, but she was thrilled her granddaughter had been saved.
She said: "God has protected this child for me. My daughter Shayma is dead, but I now have a new daughter.
"She'll call me 'mummy' just like her mother did."
But she added: "Shayma had really been looking forward to being a mother.
"What did Shayma do to deserve to die and lie under rubble for an hour without being recovered?
"She was just a young wife who had only been married a year."
Now four days old, the baby is breathing through at an oxygen mask in the hospital's maternity ward.
Abdel Karim al-Bawab, head doctor at the maternity ward, said staff were keeping a close eye on the baby to monitor her condition.
He said: "The child is in serious condition, and needs to be constantly hooked up to a breathing machine since she was oxygen-deprived between her mother's death and her birth.
"Her vital signs are stable, but she must stay here in this state for at least three more weeks."
More than 800 people have been killed in Gaza since Israel launched its military offensive on July 8 with the declared objective of stopping Hamas firing rockets into Israel. Israel has lost 36 people.
Update: Tragically, little Shayma lost her fight for life on Tuesday.