Police in the Xicheng district of the city said in a statement on Weibo that they had detained a 49-year-old male suspect surnamed Jia, who was a former fix worker at the school.
Authorities did not say what weapon, if any, was used in an attack that left three children with serious, but non-life threatening injuries.
According to the Beijing Affiliated Elementary School of Xuanwu Normal School website, it has 2,537 students and 199 teaching personnel.
A video circulating online showed the school's headmaster telling angry parents that the attack occurred on the first floor, which held Year Two classes. Another video shows anxious parents forming a large crowd outside the school's entrance, demanding details.
A Reuters witness described seeing six police cars outside the school where the attack took place.
The incident happened at around 11:15am local in the city's Xicheng district, police said.
Police declined to comment by telephone when asked about the attack.
Drone sighting stops flights out of London's Heathrow Airport
Transport Minster Chris Grayling said the military are "preparing to deploy equipment used at Gatwick should it prove necessary". Heathrow and Gatwick recently also spent millions of pounds on military-grade anti-drone equipment .
Federer claims record third Hopman Cup title in dramatic fashion
Federer said the win helped atone for a loss to the German in the semi-finals of the season-ending ATP World Tour event in London. Federer also became the first player to win successive Hopman Cups and said the records were a nice bonus for winning the title.
Trump trashes Mattis after exit: ‘What’s he done for me?’
The immediate reason for Mattis' resignation was Trump's announcement that he is ordering United States troops out of Syria. Shanahan, a former Boeing Co. executive, is confronted with the Syria pullout, a move that drew bipartisan hysteria.
All 20 of the injured children were rushed to the hospital for treatment.
The Xicheng government did not give other details of the attack, but posts on social media said the children suffered knife wounds to the head. "We have paused several operations to save all the children".
Five children were killed in November when a auto ploughed into a crowd outside a school in Huludao in Liaoning province.
It comes just months after a 39-year-old woman was reportedly held on suspicion of stabbing 14 school children in October last year in Chongqing.
The attack comes a day after a Chinese man was put to death for injuring 12 children in a knife attack at a nursery in China.