DRESDEN, Germany - A man who stabbed a pregnant Egyptian woman to death in a German courtroom in front of her husband and three-year old son was sentenced to life in prison Wednesday, a court spokesman said.

The case of Alex Wiens, 28, who has admitted holding anti-Islamic and xenophobic views, shocked Germany and incensed the Muslim world, sparking protests from Egypt to Iran.

Security has been exceptionally high for the trial, with 200 police officers securing the court in the same eastern city of Dresden where the July attack occurred. The killing took place in a different courthouse.

Wiens, a German of Russian origin, was convicted of murdering Marwa El-Sherbiny, whom he stabbed 16 times with a knife, and given the maximum penalty. He also stabbed her husband Elwy Okaz, who was trying to defend her.

Okaz was then shot in the leg by a guard who mistook him for the attacker. He appeared at the trial on crutches.

The defendant sat behind bulletproof glass for the trial, with his feet shackled, and hid his face under a hood and sunglasses.

The killing took place in a court where Wiens was appealing a conviction for insulting Sherbiny by calling her an Islamist, terrorist and slut when she asked him to make room for her son to play on swings in a playground.

In a statement read out by one of his lawyers during the trial, Wiens said he was hostile to foreigners but that was not the motive for the attack. Instead, it was his fear of the trial, and of being sent to jail.

Germany has the second-largest Muslim population in western Europe after France and some groups criticized the German government for taking several days to condemn the murder.

Media in Islamic countries have described Sherbiny as a veiled martyr and closely covered the trial.

(Reporting by Martin Schlicht; Writing by Sarah Marsh; Editing by Dominic Evans)