Ottmar Breidling, the presiding judge, said el-Hajj Dib was guilty of a "thoroughly terrorist act" and dismissed the defendant's claim that he had only deposited a mock-up of a bomb packed in a suitcase in a rail carriage to scare the German public.
"This was a crime for which only the highest penalty under the law can apply," Breidling said.
A life sentence in Germany generally amounts to 15 years in prison.
Duscha Gmel, the state prosecutor, told the court: "Germany was never closer to an Islamist attack."
El-Hajj Dib told the court last week that he had no intention of killing anyone.
"If I had really wanted the attack, I could have finished building the explosive charge correctly," he said.
He said his actions were meant as a warning after cartoons depicting the Prophet Mohammed were published in a Danish newspaper in 2005, and reprinted by other European publications.
The cartoons sparked protests across the world.
Both Dib and Hamad, who is currently serving a 12-year sentence in Beirut over the plot, had been living as students in Germany.