Rakhmat Akilov, 39, from Uzbekistan, had said he wanted to punish Sweden for joining a coalition against the Islamic State group.
In January, he was charged with terror-related murder and attempted murder for the attack with a stolen beer truck on 7 April 2017.
Akilov hijacked the vehicle outside a restaurant in central Stockholm and sped about 500m down a pedestrian street, ploughing into shoppers before crashing into a department store.
The failed asylum seeker also planned to blow himself up but failed, and caused a smaller explosion inside the truck when a device made of five gas canisters with dozens of screws, blades and smaller metal objects went off.
He was arrested the same day outside a gas station in a Stockholm suburb after he was recognised from a CCTV image and quickly admitted to being the driver.
The victims were 41-year-old British father Chris Bevington, a Belgian woman and three Swedes – including an 11-year-old girl.
Another 14 people were injured.
He was found guilty of five counts of terror-related murder, 119 counts of attempted murder and 24 cases of endangering the life of others.
More from Sweden
Murder accused Peter Madsen ‘planned to torture Kim Wall with great pleasure’
Bitcoin heist suspect escapes prison and ‘flees on plane carrying Iceland’s PM’
Madsen walked ‘determinedly and with a saw’, witness
LIVE: Kim Wall ‘was afraid to be on a submarine’
LIVE: Kim Wall was afraid to be on a submarine, murder trial told
LIVE: Submarine builder Peter Madsen tells court Kim Wall’s death was ‘horrible’
The prosecution had demanded a life sentence, while defence lawyer Johan Eriksson said his client had been cooperative and should be given a time-limited sentence.
During the court proceedings that started on 13 February and ended on 2 May, Mr Eriksson said that “Akilov took the right to determine the fate of so many people. Now it is the turn of the democratic rule of law to determine the fate of Akilov”.