The two men helped Kujtim Fejzulai to acquire weapons and ammunition before he opened fire in the Austrian capital's city centre on November 4, 2020, a court found.
Two others who helped to organise the attack, for example by plotting an escape route for Fejzulai, were handed prison terms of 19 and 20 years respectively.
A fifth and sixth suspect were cleared of direct involvement in the attack but found guilty of supporting ISIS and given two-year sentences, partially suspended.
Fejzulai was shot dead by police after killing four people in a nine-minute rampage, Austria's worst terrorist attack for decades.
The late-night verdicts from a Vienna court came after lawyers for the six suspects had argued that their clients barely knew Fejzulai and had been unaware of what he intended to do.
But the jury accepted the prosecution's case that some of them helped to supply Fejzulai with the weapons he used in the attack.
One of the men given life sentences was found to have encouraged Fejzulai up to the day of the attack and prepared the weapons he had in his flat, while another had given him guns and ammunition.
The defendant given 19 years was found to have connected Fejzulai to one of those accomplices, and helped to organise the ammunition purchase, but was spared a life sentence because of his young age.
The man sentenced to 20 years had arranged false documents to help Fejzulai escape, and helped to choose the site of the attack, the jury found.
Another suspect was accused of helping Fejzulai by chauffeuring him to a Slovakian arms dealer to buy ammunition for an AK-47 rifle, but the jury rejected that case.
The sixth defendant was cleared of the accusation that he had helped Fejzulai prepare on the day of the attack.
However, the latter two suspects were convicted of spreading ISIS propaganda.
An inquiry last month blamed failures in Austrian intelligence services for allowing Fejzulai, a dual citizen of Austria and North Macedonia, to slip through the net.
The evidence that Fejzulai had tried to buy ammunition for an AK-47 in Slovakia was not passed to prosecutors before the attack, a report said.
Fejzulai had served prison time after trying to travel to Syria, but was released in 2019.