STOCKHOLM (AP) — An Uzbek man who carried out a deadly attack on Stockholm last year swore allegiance to the Islamic State group in a video and wrote that he wanted “to scare the infidels and leave my life,” prosecutors said Tuesday as his trial began.

Rakhmat Akilov appeared before the Stockholm District Court for ramming a stolen truck into a crowd in the Swedish capital, killing five people and injuring 14 others because he wanted to punish Sweden for joining a coalition against the IS.

He is charged with terror-related murder and attempted murder. The prosecution has asked that he gets a life sentence and is extradited from Sweden.

Akilov, who has confessed to the attack, wore handcuffs as he entered the high-security courtroom.

Prosecutor Hans Ihrman described how Akilov drove a stolen beer truck into a busy Stockholm shopping street on Apr. 7 before being arrested hours later.

“The case is about 40 seconds that changed forever the lives of those who were on Drottninggatan” promenade that day, he said.

Five people were killed — a British man, a Belgian woman and three Swedes, including an 11-year-old girl.

“Yes, it was Akilov who drove the truck,” his lawyer, Johan Eriksson, told the court.

In a room adjacent to the courtroom, relatives of the victims listened quietly, some in each other’s arms.

Akilov, who turns 40 on Wednesday, was born in Uzbekistan and worked there as a construction worker. He came to Sweden in 2014 and applied for asylum, claiming he had been persecuted. His application was rejected and he was ordered to leave Sweden in December 2016.

Instead, he went underground, eluding authorities’ attempts to track him down. Sweden’s domestic intelligence agency has said it had nothing indicating that he was planning an attack.

Inside the courtroom, Akilov stared at a screen where footage from the attack — including those he made while driving the truck — were shown. The prosecutor spoke about how Akilov used 53 SIM cards and social media — including WhatsApp, Telegram, Viber, Facebook and Zello — to communicate with others about his activities.

Akilov has said he proposed carrying out an attack in Stockholm to IS on their behalf. It was not clear whether the group had accepted his offer.

Investigators have found internet chat logs with unknown people in which Akilov discussed becoming a martyr and swore allegiance to IS between Jan. 12, 2017, and the attack. They have also found a memory card with execution videos and thousands of photos, including one of IS leader Abu Bakr al-Baghdadi.

The prosecution also played a video where Akilov swore allegiance to IS. On April 6 — the eve of the attack — Akilov wrote in a chat “tomorrow, in the evening I will find a large vehicle and I will drive into a crowd with it.”

The attack shocked Swedes, who pride themselves on their open-door policies toward migrants and refugees.

In 2015, a record 163,000 asylum-seekers arrived in Sweden — the highest per capita rate in Europe. The government responded by tightening border controls and curtailing some immigrant rights.

Officials have acknowledged the difficulty of keeping tabs on rejected asylum-seekers who have been ordered to leave the country.