Berlin - A German man was on Thursday sentenced to 15 years in a psychiatric ward for fatally stabbing his four children in their sleep with a carpet knife after his wife left him.

In the gruesome case which shocked the nation, the 37-year-old murdered his three sons and 12-year-old daughter in their family home, a terrace house in Ilsede in the state of Lower Saxony.

The mother was on holiday in Denmark at the time and learnt of her childrens' deaths in a text message sent by her husband.

The man, not named under German privacy laws, who the judge said was in a near-psychotic state and therefore had reduced criminal culpability, tried to kill himself but survived with severe injuries.

Witnesses said the man had previously been known as a loving, patient and committed father who lived for his children.

A psychiatric expert told the court that the man was likely less motivated by a wish for revenge over the marital separation than by a desperate desire to be united with his children in death.

Hundreds of people had earlier joined a memorial service for the children and sent donations to the mother, who still lives in the house where the bloodbath took place. - Sapa-dpa