Stuart Harness, 34, and Gavin Humphries, 37, made petrol bombs and threw them at the Grimsby Islamic Cultural Centre while being filmed on CCTV cameras they thought were off.
They were jailed by Judge Mark Bury at Hull Crown Court after admitting arson being reckless as to whether life was endangered at an earlier hearing.
Judge Bury told the pair: "This was a crime of violence where a particular religious group was deliberately targeted in an act of retribution."
He said: "This kind of attack cannot be tolerated. A severe sentence is required to punish but, more importantly, to deter."
He jailed a third defendant, Daniel Cressey - who denied aiding and abetting the other two but was found guilty by a jury - also for three years.
Judge Bury said: "Whatever your feelings of outrage were, you should have allowed justice to take its course.
"Instead you carried out a retaliatory act of throwing petrol bombs at the Grimsby Islamic Cultural Centre.
"As is usual in these cases, the victims had nothing to do with the events that so enraged you.
"They were entirely innocent law-abiding Muslims who were practising their religion in a peaceable way."