Belgian authorities say a prisoner on day release had killed another former inmate the evening before going on a murderous rampage in Liege on Tuesday (May 29).
The man stabbed and shot dead two female police officers, and gunned down a young man in a nearby car, in the eastern city.
He was later killed by police after a shootout at a school where he had taken female employees hostage.
Prosecutors are treating it as a terrorist attack.
On Wednesday, the Islamic State group said it was responsible, without providing evidence.
The gunman attacked two female police officers — aged 45 and 53 — from behind with a knife at around 10.30am CET, seized their handguns and shot them dead.
He then shot dead a trainee teacher, 22, as he was sitting with his mother in a car nearby.
The gunman then entered a nearby secondary school, where he took a female employee hostage. A woman identified as the school cleaner has told Belgian media the man demanded to know whether she was a Muslim and freed her after she confirmed that she was.
No-one else was harmed inside the building. Pupils were moved to safety before a gun battle with police broke out that sent people in the street racing for cover.
When the attacker emerged from the school he was heard shouting "Allahu Akbar" — God is greatest in Arabic — in a video shot by local residents.
He was gunned down by police in a shootout that left four officers injured.
The attacker has been identified as 31-year-old Benjamin Herman, a drug dealer who had been let out of jail just hours before Tuesday's attack to prepare for an eventual release in 2020.
A security source told Reuters the gunman had converted to Islam while in detention where he was suspected to have been radicalised.
The Belgium native appeared to have followed online exhortations from ISIL to stab police officers and use their service weapons to shoot others, prosecutors said.
He had been in jail since 2003 having been convicted for crimes including robbery, assault and drug trafficking.
Belgium's interior minister told broadcaster RTL on Wednesday that Herman “also committed a murder the night before" the Liege attack.
Jan Jambon confirmed that the male victim was a former prisoner who did jail time with Herman. He has been named as 30 year-old Michael Wilmet, a convicted drug dealer, who the authorities say was hit over the head with a blunt object by Herman on Monday night.
Liege police posted a picture of their two fallen colleagues on Facebook, Soraya Belkacemi, 45, and Lucille Garcia, 53, paying homage to the women and saying "our entire police force is in mourning".
Belkacemi had twin daughters, aged 13, whose father, also a police officer, was killed previously.
Garcia is said to have only just married a colleague. She had a 25-year-old son and had reportedly recently become a grandmother.
The post also said that of four other injured officers, one had been discharged and the other three were recovering after surgery — all of them were "out of danger".
The third victim, 22-year-old Cyril Vangriecken, was a trainee teacher. He was with his mother in a car when the gunman shot him through the window or car door.
A tribute to the young man has been published on the website of Liege boules club, which described him as "a bright and promising young man".
"His politeness, his kindness and his simplicity were the hallmarks of his behaviour both in the sporting world and outside. He will leave a big void around him," it read.
Investigators will continue trying to flesh out the profile of the gunman, whose killing of three people in Liege was described as a "terrorist act" by Belgian courts.
Prosecutors will explore his supposed links to radical Islamists in jail, and face questions over why he had been let out for a day.
Justice Minister Koen Geens, who oversees the prison service, said he felt "responsible" for Tuesday's attack and had to examine his conscience. However he has defended the fact that Herman had been on day release.
The authorities say such practice is a common method to rehabilitate long-term prisoners in Belgium.
Concerns have been raised over the number of criminals who have been radicalised in jail and then carried out attacks after being released.
"They come in as drug dealers and leave as Salafi jihadists," a security source told Reuters.
Meanwhile, hundreds of prisoners deemed radicalised by authorities are due to be released in the coming years, Belgium's parliament warned in a report last year.