He cried: "Allahu akbar", the Arabic phrase for "God is great", several times during Tuesday's rampage, prosecutors said.
His shouts of "Allahu akbar" and contact with people considered radicalized also were factors, the magistrate said.
The attacker then ran into a nearby school and took a woman hostage before he was killed during a rescue operation mounted by special forces.
Three police officers were also attacked in Brussels in October 2016 by a man wielding a machete.
Missouri Gov. Eric Greitens resigns
Greitens said during a news conference that "the last few months have been incredibly hard ". "While I cannot force Mr. Missouri Governor Eric Greitens announced his resignation Tuesday evening from his office in Jefferson City.
Mr Jambon said Herman killed the former inmate by hitting him over the head with a blunt object. Herman then killed a man sitting in a nearby vehicle, according to CBS News.
When the assailant began shooting through a window looking on the schoolyard, Darifa started screaming, she said.
In a message on Twitter shortly after the outrage, Mrs May said: "My thoughts are with the victims of today's cowardly attack in Belgium and their grieving families". He didn't identify the police officers, but said they were both women aged 45 and 53, the latter a mother of twins.
Herman had reportedly done various stints in jail since 2003 for assault, robbery and drugs convictions.
Mr Jambon said: "There are signs he was radicalised in prison but is it that radicalisation which drove him to commit these acts?".
The View From Pluto: The Cavs' Most Improbable Title Run Yet
The Warriors and Cavaliers met twice in the regular season, but it might not be wise to read too much into the results. But at the end of the day, his athleticism allows him to play some of the premier perimeter players in our league.
In this undated handout provided by the Liege Police Department on May 30, 2018, Liege police officers Soraya Belkacemi, left, and Lucille Garcia, right, are seen in their uniforms.
He also appeared to have followed online exhortations from Islamic State to stab police officers and use their service weapons to shoot others, prosecutors said. He then gunned down Cyril Vangriecken, 22, who was in a parked auto with his mother, and fled to a nearby school, where he took a woman hostage.
Herman was later gunned down after a shoot-out between him and the police. The Liege Police Force paid tribute to its colleagues who died in the attack.
Belgian media say a gunman has shot dead two police officers and a bystander in the eastern city of Liege.
Belgian Interior Minister Jan Jambon said Belgium's Federal Crisis Centre was monitoring the situation. One video showed two police in body armour moving into position.
The latest on Chris Paul recruiting LeBron James
Morey expressed optimism in having the team back in a similar if not better position next season. That all became far more hard to impossible without Paul - and created no-win choices.
Officials said Wednesday that the death toll from the attack outside a Liege cafe might have been higher if the bar owner and a cleaning lady had acted with less skill and courage. However, Belgium's crisis center said it saw no reason to raise the country's terror threat for now.
- "No Tobacco Day" focuses on cardiovascular health
- Trump says Mueller will be ‘meddling’ with 2018 vote
- Trump, Kim raise summit hopes after days of brinkmanship
- Unseen for weeks, Melania Trump tweets she's 'feeling great'
- Moving lava threatens more homes on Hawaii's Big Island
- 3 takeaways from Game 1 vs. Warriors
- Apple's iPhone X: Attack of the Clones
- Australians will no longer be able to order from Amazon’s American site
- Roseanne Barr Says She "Begged" Ben Sherwood Not to Cancel 'Roseanne'
- Assad threatening to attack United States backed forces in Syria