Stuart Harness, 34, and Gavin Humphries, 37, made petrol bombs and threw them at the Grimsby Islamic Cultural Centre.
They were filmed by CCTV cameras they mistakenly thought they had turned off.
The pair were jailed yesterday at Hull Crown Court after admitting arson and being reckless as to whether life was endangered.
They launched two petrol bombs each at the mosque on 26 May, four days after Fusilier Rigby was murdered. They were spotted by patrolling police community support officers and followed back to Harness’s house where they were arrested.
Detectives found they had earlier inadvertently filmed themselves on a CCTV system at Harness’s home taking petrol into the house, building the bombs and leaving with them.
Jeremy Evans, prosecuting, said they thought they had turned the system off when they switched off the laptop to which it was connected.
The CCTV footage showed the whole process of making the bombs until they left in a third man’s car.
The bombs exploded outside the main doors of the mosque. Mr Evans said it was “lucky” the people in the building were just on the other side of the doors and realised quickly what was happening. They put out the flames despite being scared and there were no injuries and minimal damage.
The judge heard how both Harness and Humphries had served in the army with unblemished records.
Harness had been in the army for 13 years and experienced “active warfare” during deployments in Iraq and Afghanistan. Harness was based at Woolwich Barracks, outside which Fusilier Rigby was murdered.
Mr Evans told the court the pair threw the devices as if they were lobbing grenades, as they would have been trained to do.
Richard Hackfath, for Humphries, said his client, who served with the Royal Artillery, was not a racist and the judge noted that he had worked in Qatar, teaching Muslim children English.
Charlotte Baines, for Harness, said he apologied for his “foolish, absurd and reckless behaviour” and was “ashamed and disgusted” by what he had done. He was “struggling to understand how his personal feeling about that situation in London [the Rigby murder] transformed into him taking direct action in the way he did”.
Judge Mark Bury said the offences had been religiously aggravated.
He described the murder of Fusilier Rigby as “a truly barbaric slaughter of an innocent man”, adding that Harness’ and Humphries’ actions had been a “premeditated act of retaliation against members of the Islamic faith”.
But he said he believed they had shown genuine remorse.