Fife man Stephen Ramsay, 36, stabbed his victim in the throat at a property in Delgatie Court in February last year.
The 35-year-old woman was taken to the Victoria Hospital in Kirkcaldy where she remained for a number of weeks receiving treatment for her injuries.
Despite best efforts, the twins did not survive.
At the High Court in Aberdeen today Ramsay received an Order for Lifelong Restriction (OLR) - effectively a life term of imprisonment, under which a prisoner will only be released if he is judged fit and safe - with a punishment part of five years in prison following the attempted murder.
He also received a lifelong non-harassment order against the victim.
Inspector Paul Dick, who led this investigation, said: "When Stephen Ramsay committed this horrendous attack he was well aware that the woman was heavily pregnant and that his actions could have killed her as well as her unborn children.
"The victim has been left with permanent injuries and she has been left utterly distraught at the death of her twins. No amount of time in prison can ever undo the harm Ramsay has caused to her.
"Ramsay has been given an Order for Lifelong Restriction due to the risk he poses to the community and this means that, only after he has served his full prison sentence, will he be considered for release and only when authorities are entirely satisfied that he is safe to do so. If he is ever released he will thereafter remain under constant supervision for the rest of his life.
"I would also like to thank the police officers and staff from the Scottish Ambulance Service who were first on the scene assisting the woman and were faced with a terrible and upsetting scene. Without their quick actions the outcome could have been far more tragic.
"We are committed to bringing perpetrators of violence to justice and providing all the necessary support and assistance to victims of such offences."