BEIJING (Reuters) - A Chinese man attacked at least 20 young children at a Beijing primary school with a hammer on Tuesday, state television reported, in a rare act of violence in the capital.

Slideshow ( 5 images )

A 49-year-old man, a former maintenance worker at the school, was detained after venting his anger on the children after his work contract was not renewed, state television cited police as saying.

Twenty were taken to hospital, the government in the Xicheng district of the capital said in a post on its social media account.

Three suffered heavy injuries but their condition was stable, it said.

Police cars lined the main road close to the school when Reuters arrived at the scene.

Several police were seen coming from the school carrying items including sealed paper bags marked “physical evidence” and silver cases before driving off.

Parents waited outside for their children as the school day ended. Almost all of the parents Reuters approached declined to be interviewed.

“I heard that children were attacked (by someone) with a knife, so I’m very anxious,” said a woman surnamed Zhou as she waited for her child to finish school.

Another parent, surnamed Jia, said she was concerned about her child’s psychological wellbeing.

“Even though they were on the same floor as the one where this took place, they didn’t know anything about this. So I really don’t want this information to be spread widely so that he starts to feel scared,” she said.

The attacker, originally from northeastern Heilongjiang province, had been detained by police and an investigation was under way, state television said.

Violent crime is rare in China but there has been a series of knife and ax attacks in recent years, many targeting children.

In January 2017, a man in southern China stabbed and wounded 12 children with a vegetable knife. He was executed this month.

“People who hurt children do not deserved to be forgiven,” a social media user wrote in a post on Weibo, a Twitter-like microblog.