Six men fuelled by violent jihadist material have been jailed for a total of more than 100 years for planning to attack an English Defence League rally with guns, swords, knives and a homemade nail-bomb.

The men from the West Midlands were discovered by chance and it is feared that if their attack had been successful, inter-ethnic warfare would have erupted on Britain's streets.

At the Old Bailey on Monday, Judge Nicholas Hilliard QC sentenced the six, who had pleaded guilty to terrorist offences.

The judge said part of the reason they became involved in such a serious plot was "the tide of apparently freely available extremist material in which most of you had immersed yourselves", which he said was an issue of "continuing significance" as counter-terrorism officials continue to grapple with the phenomenon of radicalisation. The judge said that when the men planned to attack the rally last June in Dewsbury, West Yorkshire – in retaliation for what they called the EDL's "blasphemy of Allah and his messenger Muhammad" – they "anticipated that some victims may have died".

The improvised explosive device, made from fireworks, 359 nails and 93 ball bearings, would have showered those nearby with hot shrapnel, potentially maiming or killing them.

Omar Khan, 31, Jewel Uddin, 27, and Zohaib Ahmed, 22, were each sentenced to 19-and-a-half years' imprisonment, with an additional five years of restrictions on licence.

Mohammed Saud, 23, Anzal Hussain, 25, and Mohammed Hasseen, 23, were sentenced to 18 years and nine months, with an additional five years on licence.

The court heard the attack was abandoned when the group turned up two hours after the EDL demonstration had finished, on 30 June last year.

Their plans were uncovered by chance when a police officer carried out a routine stop on one of the vehicles as the men made their way back to Birmingham. The car was seized but the weapons and bomb were only discovered two days later when the vehicle was searched.

Five of the defendants had travelled in two cars from Birmingham to Dewsbury on the afternoon of 30 June with an arsenal of weapons hidden in holdalls in the boot of one of the cars.

Among the weapons were two shotguns, swords, knives, the nail bomb stuffed with shrapnel and explosives and a partially assembled pipe bomb.

Also recovered from the car were 10 printouts on A4 paper of a document addressed to the prime minister and the Queen that set out in chilling terms the gang's determination to take revenge on the "enemies of Allah" – the "English Drunkards League".

It stated: "We love death more than you love life … What we did today was a direct retaliation of your insulting of the Prophet Muhammad (peace be upon Him) & also in retaliation of your crusade against Islam/Muslims on a global scale. It is of the greatest honour for us to do what we did."

The judge said the men spent eight weeks preparing the attack and all six were found with extremist material.

Three of them had read the terrorist online magazine Inspire, which is connected to Anwar al-Awlaki, the former spiritual leader of al-Qaida in the Arabian Peninsula, who was killed in his Yemeni hideout by a US drone strike on 30 September 2011.

Awlaki's propaganda has been linked to terrorist plots in the US and UK, including the attempted murder of the Labour MP Stephen Timms in 2010.

On Uddin's mobile phone was a lecture in which the speaker said that it was right to wage war against the unbeliever. Uddin also collected components for a pipe bomb after reading instructions in Inspire.

At Hasseen's home, police found 859 files of extremist material, including some urging people to fight abroad, a digital copy of Inspire containing pipe bomb instructions and a video about IEDs. Saud had also read Inspire. The judge said of the extremist material found: "In this case, it can only have served to reinforce the defendants' resolve to behave in the hideous way that was planned".

Hilliard said that the EDL and their campaign against Muslims contained "foul and inflammatory insults", but the plot to kill had to be punished by long jail terms. He explained that remorse expressed by the defendants and a guilty plea had helped them avoid life sentences.

He said: "As a matter of generality, unlawful violence of any kind, and foul and inflammatory insults of a racial nature or directed towards a particular religious group deserve at the least unequivocal condemnation … I acknowledge the unrest and enormous distress such behaviour gives rise to. But as a response, more unlawful violence is not on the list of options."

One of the group, Uddin, was under "low-level" surveillance by the security services because of a suspected connection to a separate plot to carry out an attack rivalling the 7 July 2005 bombings – although police said there was not enough evidence against him to warrant his arrest in relation to that case.

Another, Hussain, is the brother of Ishaaq Hussain, one of those convicted in April in the same plot. A third, Ahmed, had served a prison sentence after being convicted of possession of terrorist material from the internet.

Counter-terrorism detectives said the group was not on their radar and that they knew nothing about the plot as the men set off for Dewsbury.

West Midlands assistant chief constable Marcus Beale said: "The methods they were using with their improvised explosive bomb, the firearms, the knives, would have almost certainly killed people – they'd have definitely maimed people.

"It was a horrible attack and it would have had a profound effect on many of our communities."