Stuart Harness, 34, and Gavin Humphries, 37, made petrol bombs and hurled them at the Islamic Cultural Centre in the eastern English fishing town of Grimsby on May 26. Terrified worshippers were trapped inside.
A third defendant, Daniel Cressey, was also jailed for six years for helping Harness and Humphries by driving them to the mosque.
The ex-soldiers carried out the firebombing four days after Islamic extremists Michael Adebolajo and Michael Adebowale -- who had no connection with the Grimsby mosque -- hacked soldier Lee Rigby to death outside his barracks in London.
"They were entirely innocent law-abiding Muslims who were practising their religion in a peaceable way," Bury said.
More From This Section
"This was a crime of violence where a particular religious group was deliberately targeted in an act of retribution."
He added, "A severe sentence is required to punish but, more importantly, to deter."
They were filmed making the bombs on Harness's own home security camera system, which he thought was switched off.
There were no injuries in the firebombing, which caused only minimal damage.
"Whatever your feelings of outrage were, you should have allowed justice to take its course," the judge told them.