A school cleaner taken hostage by a gunman who killed four people in the Belgian city of Liege has described how she kept the attacker away from schoolchildren.

Imaankaf Darifa, 47, had closed the doors to the school to protect pupils and teachers when she was taken hostage by Benjamin Herman, a prison inmate who Isis claimed was a “soldier of the caliphate.”

Herman, a convert to Islam, had spent most of his time in prison since 2003 and was on a two-day leave when he stabbed two police officers and used their handguns to kill them and a bystander on Tuesday.

The night before, the convict had killed a fourth person, a former cellmate who he bludgeoned to death, Jan Jambon, the country’s interior minister, said.

Belgian Special Police at the scene of the shooting in Liege, Belgium (AP Photo/Geert Vanden Wijngaert)

After stabbing the officers repeatedly from behind with a knife, stealing their handguns and shooting them as they lay on the ground, Herman shot a 22-year-old passenger in a car and shouted “Allahu akbar,” the Arabic for “God is great,” several times, authorities said.

He then entered the Lycee de Waha high school and took Ms Darifa, the cleaner, hostage.

“I told him: ‘You are in a school here, you cannot come in a school, it is not right what you are doing,”’ she told the Press Association.

Herman then asked if she was Muslim and she told him he was. He then asked if she was observing the holy month of Ramadan.

“I answered yes. So he told me, ‘I won’t harm you,”’ Ms Darifa said.

Police at the scene of the shootings in Liege (EPA)

She said Herman told her to ask the police stationed outside the school to leave.

When they refused, the gunman threw out his identity card, then, Ms Darifa said: "He walked out, and I left. Then there were guns and they killed him.”

Officials have said th death toll might have been higher if the owner of the cafe where the attack took place and Ms Darifa had acted with less skill and courage.

Belgium’s prime minister, Charles Michel, and King Philippe visited her in hospital, where she was being treated for shock.

Mr Jambon, the country's interior minister, described Ms Darifa as "very courageous."

The murdered police officers were identified as Lucile Garcia, 53, and Soraya Belkacemi, 45 (AFP/Getty Images)

The police officers have been identified as Lucile Garcia, 53, who had recently become a grandmother, and Soraya Belkacemi, 45, a mother to 13-year-old twins. The passenger in the car was named as Cyril Vangriecken, 22, who was preparing to become a primary school teacher.

The attack is being treated as “terrorist murder and attempted terrorist murder,” Belgian federal magistrate Wenke Roggen said on Wednesday.

She said the assessment was based on Herman’s actions, which she said mirrored Isis’s films calling for supporters to attack police with knives and steal their weapons.

His shouts of “Allahu akbar” and contact with people considered radicalised were also factors, the magistrate said.

The attack has shaken Belgium, which was struck by coordinated suicide attacks on the Brussels airport and underground system in March 2016, which killed 32 people and injured hundreds.