Zakariya said the ruling would be appealed within 15 days.
Hamad had confessed to planting the bombs and said the plot was a protest against cartoons that depicted Muhammad, the prophet of Islam.
Drawings of the prophet, which first appeared in a Danish newspaper in September 2005 and were republished in other European papers, sparked protests across the Muslim world.
Hamad’s father, Shahid, called the sentence against his son unfair.
“He should have been acquitted because he has nothing to do with what happened,” he said.
El-Hajdib, whose trial opened on Tuesday in Dusseldorf, faces charges on an unspecified number of counts of attempted murder and attempting to set off explosions.
“Your plan envisioned carrying out two synchronised bomb attacks and then relocating abroad,” Horst Salzmann, the prosecutor, said on Tuesday.
Hamad is not on trial in Germany as prosecutors there have said it was impossible to charge him in absentia.